Skip to content

Commit

Permalink
feat: Social Login 성공 시 사용자 email, profileUrl 받아오는 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
comst19 committed Jan 17, 2024
1 parent ee83eeb commit 7d33537
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
12 changes: 7 additions & 5 deletions frontend/ARchive/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,7 @@
android:exported="true"
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
Expand All @@ -74,7 +70,13 @@
<activity
android:name=".presentation.ui.splash.SplashActivity"
android:screenOrientation="portrait"
tools:ignore="LockedOrientationActivity">
tools:ignore="LockedOrientationActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class SignInFragment : BaseFragment<AuthViewModelImpl,FragmentSignInBinding>(R.l
navController = Navigation.findNavController(view)

socialLoginUtil = SocialLoginUtil(requireContext(), object : SocialLoginUtil.LoginCallback {
override fun onLoginSuccess(userid : String, social: AuthViewModel.Social) {
override fun onLoginSuccess(authId : String, email : String, profileUrl : String, social: AuthViewModel.Social) {
viewModel.SignInSuccess(social)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ import com.kakao.sdk.user.UserApiClient
class SocialLoginUtil(private val context: Context, private val callback: LoginCallback) {

interface LoginCallback {
fun onLoginSuccess(userId : String, social: AuthViewModel.Social)
fun onLoginSuccess(authId : String, email : String, profileUrl : String, social: AuthViewModel.Social)
fun onLoginFailure(error: Throwable)
}

private val googleSignInClient: GoogleSignInClient by lazy {
val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.requestId()
.requestProfile()
.build()
GoogleSignIn.getClient(context, gso)
}
Expand All @@ -35,6 +37,7 @@ class SocialLoginUtil(private val context: Context, private val callback: LoginC
} else if (token != null) {
//Log.e("카카오", "로그인 성공 ${token.accessToken}")
//callback.onLoginSuccess(AuthViewModel.Social.KAKAO)
kakaoGetUserInfo()
}
}
} else {
Expand All @@ -45,11 +48,26 @@ class SocialLoginUtil(private val context: Context, private val callback: LoginC
} else if (token != null) {
//Log.e("카카오", "로그인 성공 ${token.accessToken}")
//callback.onLoginSuccess(AuthViewModel.Social.KAKAO)
kakaoGetUserInfo()
}
}
}
}

private fun kakaoGetUserInfo() {
UserApiClient.instance.me { user, error ->
if (error != null) {
Log.e("카카오", "사용자 정보 요청 실패", error)
} else if (user != null) {
Log.i("카카오", "사용자 정보 요청 성공" +
"\n회원번호: ${user.id}" +
"\n이메일: ${user.kakaoAccount?.email}" +
"\n프로필사진: ${user.kakaoAccount?.profile?.thumbnailImageUrl}")
//callback.onLoginSuccess(user.id.toString(),AuthViewModel.Social.KAKAO)
}
}
}

fun googleSignIn(): Intent {
return googleSignInClient.signInIntent
}
Expand All @@ -58,6 +76,9 @@ class SocialLoginUtil(private val context: Context, private val callback: LoginC
try {
val account = completedTask.getResult(ApiException::class.java)
//Log.d("구글", "로그인 성공: ${account.idToken}")
Log.d("구글 id", "로그인 성공: ${account.id}")
Log.d("구글 email", "로그인 성공: ${account.email}")
Log.d("구글 프로필", "로그인 성공: ${account.photoUrl}")
//callback.onLoginSuccess(AuthViewModel.Social.GOOGLE)
} catch (e: ApiException) {
//Log.w("구글", "signInResult:failed code=" + e.statusCode)
Expand Down

0 comments on commit 7d33537

Please sign in to comment.