인증 연동
아이디/비밀번호 인증 및 생체로그인, 애플로그인, 구글로그인, 카카오톡 로그인, 네이버 로그인 등 다양한 로그인 방법을 샘플소스와 함께 안내합니다.
Last updated
아이디/비밀번호 인증 및 생체로그인, 애플로그인, 구글로그인, 카카오톡 로그인, 네이버 로그인 등 다양한 로그인 방법을 샘플소스와 함께 안내합니다.
Last updated
yamlCopy codedependencies:
google_sign_in: ^5.7.0Future<void> _loginWithGoogle() async {
try {
await _googleSignIn.signIn();
if (await GoogleSignIn().isSignedIn()) {
UiUxData.navigatorKey!.currentContext
?.read<AuthService>()
.isAuthenticated = true;
widget.onLoginResult?.call(true);
print('구글 로그인 성공');
} else {
print('구글 로그인 실패');
}
} catch (error) {
print(error);
}
}yamlCopy codedependencies:
kakao_flutter_sdk: ^0.10.0Future<void> _loginWithKakao() async {
if (await isKakaoTalkInstalled()) {
try {
await UserApi.instance.loginWithKakaoTalk();
UiUxData.navigatorKey!.currentContext
?.read<AuthService>()
.isAuthenticated = true;
widget.onLoginResult?.call(true);
print('카카오톡으로 로그인 성공');
} catch (error) {
print('카카오톡으로 로그인 실패 $error');
if (error is PlatformException && error.code == 'CANCELED') {
return;
}
try {
await UserApi.instance.loginWithKakaoAccount();
UiUxData.navigatorKey!.currentContext
?.read<AuthService>()
.isAuthenticated = true;
widget.onLoginResult?.call(true);
print('카카오계정으로 로그인 성공');
} catch (error) {
print('카카오계정으로 로그인 실패 $error');
}
}
} else {
try {
await UserApi.instance.loginWithKakaoAccount();
UiUxData.navigatorKey!.currentContext
?.read<AuthService>()
.isAuthenticated = true;
widget.onLoginResult?.call(true);
print('카카오계정으로 로그인 성공');
} catch (error) {
print('카카오계정으로 로그인 실패 $error');
}
}
}yamlCopy codedependencies:
flutter_naver_login: ^4.0.0Future<void> _loginWithNaver() async {
try {
await FlutterNaverLogin.logIn();
} catch (error) {
print(error);
}
NaverAccessToken res = await FlutterNaverLogin.currentAccessToken;
if (res.accessToken != '') {
UiUxData.navigatorKey!.currentContext
?.read<AuthService>()
.isAuthenticated = true;
widget.onLoginResult?.call(true);
print('네이버 로그인 성공');
} else if (res.accessToken == '') {
print('네이버 로그인 실패');
}
}yamlCopy codedependencies:
sign_in_with_apple: ^3.0.0Future<UserCredential> _loginWithApple() async {
final rawNonce = generateNonce();
final nonce = sha256ofString(rawNonce);
final appleCredential = await SignInWithApple.getAppleIDCredential(
scopes: [
AppleIDAuthorizationScopes.email,
AppleIDAuthorizationScopes.fullName,
],
webAuthenticationOptions: WebAuthenticationOptions(
clientId: 'com.dubhesoft.aliothv2',
redirectUri: Uri.parse(
'https://flutter-sign-in-dc1ef.firebaseapp.com/__/auth/handler'),
),
nonce: nonce,
);
final oauthCredential = OAuthProvider("apple.com").credential(
idToken: appleCredential.identityToken,
rawNonce: rawNonce,
);
return await FirebaseAuth.instance.signInWithCredential(oauthCredential);
}