0 purchases
supabase 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({
required final NavigatorState navigator,
}) => use(
LifeHook(
debugLabel: 'AuthRequiredState',
state: AuthRequiredState(
navigator: navigator,
),
),
);
class AuthRequiredState extends SupabaseAuthRequiredLifeState {
AuthRequiredState({
required this.navigator,
});
final NavigatorState navigator;
@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
.pushNamedAndRemoveUntil('/login', (final route) => false);
}
}
}
copied to clipboard
or use
AuthState useAuthState({
required NavigatorState navigator,
}) => use(
LifeHook(
debugLabel: 'AuthState',
state: AuthState(
navigator: navigator,
),
),
);
class AuthState extends SupabaseAuthLifeState {
AuthRequiredState({
required this.navigator,
});
final NavigatorState navigator;
@override
void onUnauthenticated() {
if (mounted) {
navigator
.pushNamedAndRemoveUntil('/', (final route) => false);
}
}
@override
void onAuthenticated(final Session session) {
if (mounted) {
navigator
.pushNamedAndRemoveUntil('/', (final route) => false);
}
}
@override
void onPasswordRecovery(final Session session) {}
@override
void onErrorAuthenticating(final String message) {
navigator.context.showErrorSnackBar(message: message);
}
}
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.