Skip to content

Instantly share code, notes, and snippets.

@DmitrySikorsky
Created December 23, 2022 20:32
Show Gist options
  • Save DmitrySikorsky/7f3f3f98da18f860d93040997c74b3cd to your computer and use it in GitHub Desktop.
Save DmitrySikorsky/7f3f3f98da18f860d93040997c74b3cd to your computer and use it in GitHub Desktop.
Future validateEmailWithOAuth2AndLogin(LoginMethod loginMethod) async {
// Creates an empty email validation token on server-side so we have its ID
EmailValidationToken emailValidationToken = await beginOAuth2EmailValidation(loginMethod);
String url = 'https://auth.youapp.com/?${kIsWeb ? 'platform=web&' : ''}provider=${loginMethod.name}&token=${emailValidationToken.id}';
if (await canLaunchUrlString(url)) {
// Open the URL in a new browser window on all the platforms except web
await launchUrlString(
url,
mode: kIsWeb ? LaunchMode.platformDefault : LaunchMode.externalApplication,
webOnlyWindowName: '_self',
);
}
// On web user leaves the app while signing in, so we do not need to check the email validation token state
if (kIsWeb) return;
DateTime start = DateTime.now();
_timer = Timer.periodic(
const Duration(seconds: 3),
(timer) async {
if ((await endOAuth2EmailValidation(loginMethod, emailValidationToken.id!))?.email?.isNotEmpty == true) {
_timer?.cancel();
await loginWithValidatedEmail(emailValidationToken);
}
},
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment