signInAnonymous method
Authenticates a user anonymously.
You need to make sure anonymous signin is enabled via
Nhost dashboard -> settings -> Sign in methods -> Anonymous Users
Throws an NhostException
if sign in fails.
Implementation
@override
Future<void> signInAnonymous(
String? displayName,
String? locale,
Map<String, dynamic>? metadata,
) async {
log.finer('Attempting sign in anonymously');
AuthResponse? res;
try {
res = await _apiClient.post(
'/signin/anonymous',
jsonBody: {
if (displayName != null) 'displayName': displayName,
if (locale != null) 'locale': locale,
if (metadata != null) 'metadata': metadata
},
responseDeserializer: AuthResponse.fromJson,
);
} catch (e, st) {
log.finer('Sign in anonymously failed', e, st);
await clearSession();
rethrow;
}
if (res != null) {
log.finer('Sign in anonymously successful');
await setSession(res.session!);
}
}