supabase_hooks 0.0.6
supabase_hooks: ^0.0.6 copied to clipboard
Unofficial Flutter Supabase life cycle adaptation for flutter_hooks.
Unofficial Supabase life cycle adaptation for flutter_hooks. See more in the original package: https://github.com/supabase/supabase-flutter
Note: This library is completely experimental and not recommended for production usage.
The idea is the same as in LifeHook, except that you can override more methods, specific to Supabase Auth life cycle
AuthRequiredState useAuthRequiredState() => use(
ContextfulLifeHook(
debugLabel: 'AuthRequiredState',
state: AuthRequiredState(),
),
);
class AuthRequiredState extends SupabaseAuthRequiredLifeState {
@override
void onUnauthenticated() {
/// Users will be sent back to the LoginPage if they sign out.
if (mounted) {
/// Users will be sent back to the LoginPage if they sign out.
Navigator.of(context)
.pushNamedAndRemoveUntil('/login', (final route) => false);
}
}
}
copied to clipboard
or use
AuthState useAuthState() => use(
ContextfulLifeHook(
debugLabel: 'AuthState',
state: AuthState(),
),
);
class AuthState extends SupabaseAuthLifeState {
@override
void onUnauthenticated() {
if (mounted) {
Navigator.of(context)
.pushNamedAndRemoveUntil('/', (final route) => false);
}
}
@override
void onAuthenticated(final Session session) {
if (mounted) {
Navigator.of(context)
.pushNamedAndRemoveUntil('/', (final route) => false);
}
}
@override
void onPasswordRecovery(final Session session) {}
@override
void onErrorAuthenticating(final String message) {
context.showErrorSnackBar(message: message);
}
}
copied to clipboard