recoverSession static method
User?
recoverSession(
- dynamic apiInstance
)
Implementation
static User? recoverSession(apiInstance) {
if (currentUser != null) {
return currentUser;
}
final json = localStorage.getString(storageKey);
if (isBrowser && json != null) {
try {
final data = jsonDecode(json);
final url = data['url'];
final token = data['token'];
final audience = data['audience'];
if (!url || !token) {
return null;
}
final api = apiInstance ??
Dio(
url,
);
return User(api: api, tokenResponse: token, aud: audience)
._saveUserData(attributes: data, fromStorage: true);
} catch (error) {
debugPrint('Gotrue-js: Error recovering session: $error');
return null;
}
}
return null;
}