Hey, I managed to get native Google Sign-In working with Appwrite custom tokens and Riverpod/GoRouter, and I’m stuck on three things:
1) SDK user identification/reset without authStateChanges Stream
I need to call sdkIdentificationService.identifyUser(userId) (e.g. RevenueCat, OneSignal, Sentry, PostHog) when the user signs in or out, and also after app startup to pick up an existing session.
- When should I run identify/reset?
- On app startup
- On manual login/logout
- which idk if should be called when deleting user or not (question 3)
- Do I need to hook into some other events, or will Appwrite handle that under the hood? (might be tied to 3rd question)
2) Routing without authStateChanges stream
Previously I used a refreshListenable to rebuild GoRouter and in its redirect I got user synchronously final isLoggedIn = authRepository.currentUser != null;. Now, since it's not possible with appwrite's sdk, I came up (or AI did) with something like this:
@riverpod
class AuthState extends _$AuthState {
FutureOr<User?> build() => ref.read(authRepo).getCurrentUser();
Future<void> signIn() async {
state = const AsyncValue.loading();
await ref.read(authRepo).signInWithGoogle();
final user = await ref.read(authRepo).getCurrentUser();
state = AsyncValue.data(user);
unawaited(sdkIdentificationService.identifyUser(user!.$id));
}
Future<void> signOut() async {
await ref.read(authRepo).signOut();
state = const AsyncValue.data(null);
unawaited(sdkIdentificationService.resetUser());
}
}
@riverpod
GoRouter router(Ref ref) {
final auth = ref.watch(authStateProvider);
final onboard = ref.watch(onboardingProvider);
final premium = ref.watch(premiumProvider);
return GoRouter(
initialLocation: '/loading',
redirect: (ctx, state) {
if (auth.isLoading) return '/loading';
final loggedIn = auth.value != null;
// Onboarding âž” Paywall âž” Login âž” Home
// ...
return null;
},
routes: [ /* … */ ],
);
}
I’ve heard rebuilding/disposing the router on every auth change is very bad practice.
What’s the recommended pattern for conditional redirects (Onboarding → Paywall → Login → Home) without an authStateChanges stream or a synchronous user provider, since appwrite sdk doesn't provide them?
3) Deleting a user
When I call my server function to delete a user, do I need to explicitly delete their Appwrite session afterward on client, or does the SDK automatically invalidate it? Should my redirect logic account for this somehow?
Recommended threads
- Introducing new string column types made...
Adding new string types is hugely bennificial! Unfortunately it made the current column types not editable to change their types to the new longer field types.
- there is critical problem in this part
when user update the integer and double both get error not update or upload
- how can i make a relationship between a ...
i want to relate the $id from users auth table in appwrite with other column in my table user_profile. because is the same user... how can i have exactly the s...