getAccessTokenWithAuth method
Future<String?>
getAccessTokenWithAuth(
- BuildContext context, {
- String? email,
- bool forceWebView = false,
Gets a valid access token with automatic re-authentication This version requires BuildContext for UI navigation
email
- Optional email to pre-fill in the authentication form
forceWebView
- If true, skips refresh token logic and forces WebView sign-in
Returns:
- Valid access token if available, refreshed, or user re-authenticates
- null only if user cancels the authentication flow
Implementation
Future<String?> getAccessTokenWithAuth(BuildContext context, {String? email, bool forceWebView = false}) async {
// If forceWebView is true, skip token refresh and go directly to WebView
if (forceWebView) {
debugPrint('[INFO] Force WebView authentication requested');
final tokens = await signIn(context, email: email, forceWebView: true);
return tokens?['accessToken'];
}
// First try without UI
final token = await getAccessToken();
if (token != null) return token;
// If no valid token, trigger sign-in flow
debugPrint('[INFO] No valid token available, triggering sign-in');
final tokens = await signIn(context, email: email, forceWebView: false);
return tokens?['accessToken'];
}