diff --git a/lib/core/enums/sns_provider_type.dart b/lib/core/enums/sns_provider_type.dart index 550d43a..73c0c7f 100644 --- a/lib/core/enums/sns_provider_type.dart +++ b/lib/core/enums/sns_provider_type.dart @@ -2,7 +2,7 @@ import 'package:freezed_annotation/freezed_annotation.dart'; enum SnsProviderType { @JsonValue('kakao') - kakao(providerId: 'kakao.com'), + kakao(providerId: 'oidc.kakao'), @JsonValue('google') google(providerId: 'google.com'), @JsonValue('apple') diff --git a/lib/features/auth/data/remote/auth_remote_data_source_impl.dart b/lib/features/auth/data/remote/auth_remote_data_source_impl.dart index c891c6f..a6a0a1f 100644 --- a/lib/features/auth/data/remote/auth_remote_data_source_impl.dart +++ b/lib/features/auth/data/remote/auth_remote_data_source_impl.dart @@ -3,6 +3,7 @@ import 'package:flutter/services.dart'; import 'package:google_sign_in/google_sign_in.dart'; import 'package:kakao_flutter_sdk_user/kakao_flutter_sdk_user.dart'; import 'package:pets_next_door_flutter/app/env/flavors.dart'; +import 'package:pets_next_door_flutter/core/enums/sns_provider_type.dart'; import 'package:pets_next_door_flutter/core/network_handling/app_dio.dart'; import 'package:pets_next_door_flutter/core/network_handling/exceptions/custom_exception.dart'; import 'package:pets_next_door_flutter/features/auth/api/auth_api.dart'; @@ -41,14 +42,11 @@ final class AuthRemoteDataSourceImpl implements AuthRemoteDataSource { @override Future signInWithKakao() async { - String customToken; + OAuthToken oAuthToken; if (await isKakaoTalkInstalled()) { try { - customToken = await UserApi.instance - .loginWithKakaoAccount() - .then((oAuthToken) => _getFirebaseAuthToken(oAuthToken)) - .then((customToken) => customToken); + oAuthToken = await UserApi.instance.loginWithKakaoTalk(); } catch (error) { // 사용자가 카카오톡 설치 후 디바이스 권한 요청 화면에서 로그인을 취소한 경우, // 의도적인 로그인 취소로 보고 카카오계정으로 로그인 시도 없이 로그인 취소로 처리 (예: 뒤로 가기) @@ -58,10 +56,7 @@ final class AuthRemoteDataSourceImpl implements AuthRemoteDataSource { // 카카오톡에 연결된 카카오계정이 없는 경우, 카카오계정으로 로그인 try { - customToken = await UserApi.instance - .loginWithKakaoAccount() - .then((oAuthToken) => _getFirebaseAuthToken(oAuthToken)) - .then((customToken) => customToken); + oAuthToken = await UserApi.instance.loginWithKakaoAccount(); } catch (error) { // print('카카오계정으로 로그인 실패 $error'); throw error; @@ -70,25 +65,25 @@ final class AuthRemoteDataSourceImpl implements AuthRemoteDataSource { } else { try { // print('카카오계정으로 로그인 성공'); - customToken = await UserApi.instance - .loginWithKakaoAccount() - .then((oAuthToken) => _getFirebaseAuthToken(oAuthToken)) - .then((customToken) => customToken); - return _firebaseAuth.signInWithCustomToken(customToken); + oAuthToken = await UserApi.instance.loginWithKakaoAccount(); + // return _firebaseAuth.signInWithoAuthToken(oAuthToken); } catch (error) { throw error; } } - return _firebaseAuth.signInWithCustomToken(customToken); + + final credential = + OAuthProvider(SnsProviderType.kakao.providerId).credential( + idToken: oAuthToken.idToken, + ); + + final userCredential = await _firebaseAuth.signInWithCredential(credential); + + return userCredential; } @override Future signOut() { return _firebaseAuth.signOut(); } - - Future _getFirebaseAuthToken(OAuthToken oAuthToken) async { - final customToken = await _authAPI.customToken(oAuthToken.accessToken); - return customToken; - } } diff --git a/lib/features/auth/repositories/auth_repository.dart b/lib/features/auth/repositories/auth_repository.dart index fbfe45d..f8db865 100644 --- a/lib/features/auth/repositories/auth_repository.dart +++ b/lib/features/auth/repositories/auth_repository.dart @@ -1,10 +1,8 @@ import 'package:firebase_auth/firebase_auth.dart'; -import 'package:kakao_flutter_sdk_user/kakao_flutter_sdk_user.dart'; import 'package:pets_next_door_flutter/core/enums/sns_provider_type.dart'; import 'package:pets_next_door_flutter/core/utils/result.dart'; abstract interface class AuthRepository { Future> signInOAuth(SnsProviderType provider); Future> signOut(); - Future> customToken(OAuthToken oAuthToken); } diff --git a/lib/features/auth/repositories/auth_repository_impl.dart b/lib/features/auth/repositories/auth_repository_impl.dart index f2be49e..2d54e06 100644 --- a/lib/features/auth/repositories/auth_repository_impl.dart +++ b/lib/features/auth/repositories/auth_repository_impl.dart @@ -1,5 +1,4 @@ import 'package:firebase_auth/firebase_auth.dart'; -import 'package:kakao_flutter_sdk_auth/src/model/oauth_token.dart'; import 'package:pets_next_door_flutter/core/enums/sns_provider_type.dart'; import 'package:pets_next_door_flutter/core/utils/result.dart'; import 'package:pets_next_door_flutter/features/auth/data/remote/auth_remote_data_source.dart'; @@ -39,10 +38,4 @@ final class AuthRepositoryImpl implements AuthRepository { return Result.failure(e); } } - - @override - Future> customToken(OAuthToken oAuthToken) { - // TODO: implement customToken - throw UnimplementedError(); - } } diff --git a/lib/features/auth/usecases/get_custom_token_use_case.dart b/lib/features/auth/usecases/get_custom_token_use_case.dart deleted file mode 100644 index a56b391..0000000 --- a/lib/features/auth/usecases/get_custom_token_use_case.dart +++ /dev/null @@ -1,17 +0,0 @@ -import 'package:firebase_auth/firebase_auth.dart'; -import 'package:kakao_flutter_sdk_user/kakao_flutter_sdk_user.dart'; -import 'package:pets_next_door_flutter/core/utils/result.dart'; -import 'package:pets_next_door_flutter/features/auth/repositories/auth_repository.dart'; - -final class GetCustomTokenUseCase { - const GetCustomTokenUseCase( - this._authRepository, - ); - - final AuthRepository _authRepository; - - Future> call(OAuthToken oAuthToken) async { -// TODO: 커스텀 토큰 발급 로직 붙이기 - throw UnimplementedError(); - } -} diff --git a/lib/presentation/pages/sign_in/widgets/start_with_kakao_button.dart b/lib/presentation/pages/sign_in/widgets/start_with_kakao_button.dart index eab6c1f..71f9f04 100644 --- a/lib/presentation/pages/sign_in/widgets/start_with_kakao_button.dart +++ b/lib/presentation/pages/sign_in/widgets/start_with_kakao_button.dart @@ -16,9 +16,7 @@ class StartWithKakaoButton extends ConsumerWidget with SignInEvent { Widget build(BuildContext context, WidgetRef ref) { return GestureDetector( onTap: () async { - // TODO: 아직 CustomToken 발급 API가 나오지 않아서 불가능 - ToastService.show(NormalToast(message: '현재 카카오 로그인이 불가합니다.')); - // await onTapSignInWithKakao(ref); + await onTapSignInWithKakao(ref); }, child: SvgPicture.asset(PNDSvgs.kakao), ); diff --git a/lib/presentation/pages/splash/splash_event.dart b/lib/presentation/pages/splash/splash_event.dart index 49993c8..0608505 100644 --- a/lib/presentation/pages/splash/splash_event.dart +++ b/lib/presentation/pages/splash/splash_event.dart @@ -20,7 +20,7 @@ mixin class SplashEvent implements _SplashEvent { final userData = await ref.read(userDataProvider.future).onError((error, stackTrace) { - ref.context.goNamed(AppRoute.signIn.name); + return null; }); if (userData != null) {