Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(firebase_login): add firebase login example app #3946

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

thisissandipp
Copy link

Description

Adds a Flutter app example that demonstrates how to handle authentication with Firebase using Riverpod.

  • sign up, and sign in with email and password
  • sign in with google
  • error handling, listening to the error message, and showing with a SnackBar
  • navigation based on the user's authentication state

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]).

  • I have updated the CHANGELOG.md of the relevant packages.
    Changelog files must be edited under the form:

    ## Unreleased fix/major/minor
    
    - Description of your change. (thanks to @yourGithubId)
  • If this contains new features or behavior changes,
    I have updated the documentation to match those changes.

Copy link

coderabbitai bot commented Jan 21, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@@ -0,0 +1 @@
{"flutter":{"platforms":{"android":{"default":{"projectId":"fb-login-riverpod","appId":"1:359355392679:android:942c58c04ec3c1f105f182","fileOutput":"android/app/google-services.json"}},"ios":{"default":{"projectId":"fb-login-riverpod","appId":"1:359355392679:ios:3e31b15579c4b6e005f182","uploadDebugSymbols":false,"fileOutput":"ios/Runner/GoogleService-Info.plist"}},"dart":{"lib/firebase_options.dart":{"projectId":"fb-login-riverpod","configurations":{"android":"1:359355392679:android:942c58c04ec3c1f105f182","ios":"1:359355392679:ios:3e31b15579c4b6e005f182"}}}}}}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't commit this

// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.

import 'package:flutter/material.dart';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either write proper tests or delete this

@rrousselGit
Copy link
Owner

I don't like the proposed folder architecture. Please don't use kind-based folders such as models/ providers/ repositories.

Instead use feature-based folders like home/login_page/settings/ ...

@@ -0,0 +1,70 @@
// File generated by FlutterFire CLI.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't commit this

@@ -0,0 +1,40 @@
import 'dart:developer';

import 'package:flutter_riverpod/flutter_riverpod.dart';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't useful in the context of a Firebase example

colorScheme: ColorScheme.fromSeed(seedColor: Colors.indigo),
useMaterial3: false,
),
home: authState.when(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use .when

Instead use switch (authState)

@rrousselGit
Copy link
Owner

Thanks for this!

I gave a very quick look at the current state, and suggested broad changes. I'll look move closely at the details once we agree on the basics :)

Note: It'd be useful to update the README with:

  • instructions on how folks can run the example (so using setting up their firebase.json & co)
  • screenshots of the example in various scenarios, to allow folks to easily see what the example can do

@thisissandipp
Copy link
Author

Thanks for the quick review and feedback, Remi.

I'll make the changes as suggested, and I'll make sure to verify the architecture with you before I start moving things around, so we’re on the same page. I'll add instructions to the README as well.

@rrousselGit
Copy link
Owner

Cool :)

If you have any doubt, feel free to ask questions!

@thisissandipp
Copy link
Author

@rrousselGit I have considered your suggestions and come up with this structure, what do you think about it?

lib/
├── auth/
│   ├── auth_repository.dart
│   ├── user.dart
├── app/
│   ├── app_state.dart  // e.g., app state provider (auth state can be renamed)
│   ├── app.dart   // MaterialApp widget, route initialization
├── sign_in/
│   ├── sign_in_page.dart
│   ├── sign_in_state.dart // Providers related to sign-in
├── sign_up/
│   ├── sign_up_page.dart
│   ├── sign_up_state.dart // Providers related to sign-up
├── home/
│   ├── home_page.dart
├── main.dart
├── provider_observer.dart

Also, I noticed your comment regarding app_provider_observer.dart is not useful in this context. It can help debug during the development process.

If you feel it doesn't add enough value here, I'm happy to remove it! I just thought it might be beneficial to keep it for the debugging phase and as a teaching point for others reviewing the example.

@rrousselGit
Copy link
Owner

rrousselGit commented Jan 23, 2025

@rrousselGit I have considered your suggestions and come up with this structure, what do you think about it?

Must better!

Also, I noticed your comment regarding app_provider_observer.dart is not useful in this context. It can help debug during the development process.

If you feel it doesn't add enough value here, I'm happy to remove it! I just thought it might be beneficial to keep it for the debugging phase and as a teaching point for others reviewing the example.

I think it's better to remove it.

IMO, less is more. The more noise we add, the harder it is for people to find what they are looking for.
In that sense, I'd even consider removing the snackbar logic.

Demonstrating how to do those things is valuable. But it should likely be a separate example instead.
One example = one goal.

This one is about Firebase auth.

We can have another example for demonstrating logging (including Crashlytics interaction).
And another one for how to deal with loading/error pages ; be it snackbars or "Oopsy" screens.

If this example contains something, it should be closely related to Firebase Auth.

@rrousselGit
Copy link
Owner

Actually about the folder structure, I'd still change a few things.

What I'd personally do is:

lib/
├── sign_in.dart // Both the view + provider
├── sign_up.dart // Both the view + provider again
├── home.dart // View + whatever home-state there is
├── main.dart // Including whatever was from the proposed "app" folder"

For UI, I usually go with "one file per route".

It's good to keep the provider and its view in the same file. No need to separate them

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants