Skip to content

Instantly share code, notes, and snippets.

@coder-Aayush
coder-Aayush / cloudSettings
Last active September 2, 2022 14:43 — forked from MWins/project-ideas01.md
Back end Projects - list
{"lastUpload":"2021-08-04T16:34:11.569Z","extensionVersion":"v3.4.3"}
@coder-Aayush
coder-Aayush / pubspec.yaml
Last active November 2, 2022 12:13
Firebase Auth using Riverpod
name: flutter_firebase_riverpod
description: A new Flutter project.
version: 1.0.0+1
environment:
sdk: '>=2.18.1 <3.0.0'
dependencies:
flutter:
@coder-Aayush
coder-Aayush / app_state.dart
Last active November 3, 2022 03:36
Riverpod State Management
import 'package:freezed_annotation/freezed_annotation.dart';
part 'app_state.freezed.dart';
@freezed
class AppState<T> with _$AppState<T> {
const factory AppState.initial() = _AppStateInitial;
const factory AppState.loading() = _AppStateLoading;
import 'package:hooks_riverpod/hooks_riverpod.dart';
final firebaseAuthProvider =
Provider<FirebaseAuth>((ref) => FirebaseAuth.instance);
// register others providers
final firebaseFirestoreProvider =
Provider<FirebaseFirestore>((ref) => FirebaseFirestore.instance);
@coder-Aayush
coder-Aayush / auth_remote_source.dart
Last active November 8, 2022 04:45
Authentication using Firebase
class AuthRemoteSource {
final FirebaseAuth _firebaseAuth;
final Ref _ref; // use for reading other providers
AuthRemoteSource(this._firebaseAuth, this._ref);
}
@coder-Aayush
coder-Aayush / auth_remote_source.dart
Last active November 8, 2022 04:57
Authentication using Firebase
Future<Either<String, User>> signup(
{required String email, required String password}) async {
try {
final response = await _firebaseAuth.createUserWithEmailAndPassword(
email: email, password: password);
return right(response.user!);
} on FirebaseAuthException catch (e) {
return left(e.message ?? 'Failed to Signup.');
}
}
@coder-Aayush
coder-Aayush / auth_remote_source.dart
Created November 8, 2022 05:03
Authentication using Firebase
Future<Either<String, User?>> login(
{required String email, required String password}) async {
try {
final response = await _firebaseAuth.signInWithEmailAndPassword(
email: email,
password: password,
);
return right(response.user);
} on FirebaseAuthException catch (e) {
return left(e.message ?? 'Failed to Login');
@coder-Aayush
coder-Aayush / auth_remote_source.dart
Created November 8, 2022 05:11
Authentication using Firebase (Google)
Future<Either<String, User>> continueWithGoogle() async {
try {
final googleSignIn = GoogleSignIn();
final GoogleSignInAccount? googleUser = await googleSignIn.signIn();
if (googleUser != null) {
final GoogleSignInAuthentication googleAuth =
await googleUser.authentication;
final AuthCredential credential = GoogleAuthProvider.credential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
@coder-Aayush
coder-Aayush / auth_remote_source.dart
Created November 12, 2022 11:58
Auth Remote Source (Firebase)
import 'package:dartz/dartz.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
class AuthDataSource {
final FirebaseAuth _firebaseAuth;
final Ref _ref; // use for reading other providers
AuthDataSource(this._firebaseAuth, this._ref);
@coder-Aayush
coder-Aayush / auth_remote_source.dart
Created November 12, 2022 12:36
Auth Remote Source (Firebase)
final authDataSourceProvider = Provider<AuthDataSource>(
(ref) => AuthDataSource(ref.read(firebaseAuthProvider), ref),
);