signInByGithub method
Future<AuthResponse<T> >
signInByGithub({
- OAuthAuthenticator? authenticator,
- bool storeToken = false,
override
Implementation
@override
Future<AuthResponse<T>> signInByGithub({
OAuthAuthenticator? authenticator,
bool storeToken = false,
}) async {
try {
emit(const AuthResponse.loading(AuthProviders.github, AuthType.oauth));
final response = await authHandler.signInWithGithub();
final raw = response.data;
if (raw != null && raw.credential != null) {
final current = await authHandler.signInWithCredential(
credential: raw.credential!,
);
if (current.isSuccessful) {
final result = current.data?.user;
if (result != null) {
final user = (authenticator ?? Authenticator.empty()).copy(
id: result.uid,
accessToken: storeToken ? raw.accessToken : null,
idToken: storeToken ? raw.idToken : null,
email: raw.email ?? result.email,
name: raw.name ?? result.displayName,
phone: result.phoneNumber,
photo: raw.photo ?? result.photoURL,
provider: AuthProviders.github.name,
loggedIn: true,
loggedInTime: Entity.generateTimeMills,
verified: true,
);
return _update(
id: user.id,
creates: user.source,
updates: {
...user.extra ?? {},
AuthKeys.i.loggedIn: true,
AuthKeys.i.loggedInTime: Entity.generateTimeMills,
},
).then((value) {
return emit(AuthResponse.authenticated(
value,
msg: msg.signInWithGithub.done,
provider: AuthProviders.github,
type: AuthType.oauth,
));
});
} else {
return emit(AuthResponse.failure(
msg.authorization,
provider: AuthProviders.github,
type: AuthType.oauth,
));
}
} else {
return emit(AuthResponse.failure(
current.exception,
provider: AuthProviders.github,
type: AuthType.oauth,
));
}
} else {
return emit(AuthResponse.failure(
response.exception,
provider: AuthProviders.github,
type: AuthType.oauth,
));
}
} catch (_) {
return emit(AuthResponse.failure(
msg.signInWithGithub.failure ?? _,
provider: AuthProviders.github,
type: AuthType.oauth,
));
}
}