feat: 로그인 화면
This commit is contained in:
68
src/features/auth/hooks/useSocialLogin.ts
Normal file
68
src/features/auth/hooks/useSocialLogin.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
import { useState } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { authApi } from '../api/authApi';
|
||||
|
||||
export const useSocialLogin = () => {
|
||||
const router = useRouter();
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
/**
|
||||
* [비즈니스 로직 1] 플랫폼별 소셜 SDK에서 받은 토큰을 백엔드로 보내어 VibeRoom JWT를 얻어오는 공통 함수
|
||||
*/
|
||||
const handleSocialLogin = async (provider: 'google' | 'apple' | 'facebook', socialToken: string) => {
|
||||
setIsLoading(true);
|
||||
setError(null);
|
||||
|
||||
try {
|
||||
// 1. 백엔드로 소셜 토큰 전송 (토큰 교환)
|
||||
const response = await authApi.loginWithSocial({
|
||||
provider,
|
||||
token: socialToken,
|
||||
});
|
||||
|
||||
// 2. 응답받은 VibeRoom 전용 토큰을 로컬에 저장 (TODO: 실제로는 Zustand/Cookie에 저장)
|
||||
console.log(`[${provider}] 백엔드 연동 성공! JWT:`, response.accessToken);
|
||||
// ex) useAuthStore.getState().setToken(response.accessToken);
|
||||
|
||||
// 3. 성공 후 메인 대시보드 화면으로 이동
|
||||
router.push('/dashboard');
|
||||
} catch (err) {
|
||||
console.error(`[${provider}] 로그인 실패:`, err);
|
||||
setError('로그인에 실패했습니다. 다시 시도해 주세요.');
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* [비즈니스 로직 2] UI 컴포넌트(View)에서 호출할 개별 플랫폼 로그인 함수들
|
||||
* 향후 여기에 구글/애플/페이스북의 실제 프론트엔드 SDK 코드가 들어갑니다.
|
||||
*/
|
||||
const loginWithGoogle = async () => {
|
||||
// TODO: Google Identity Services(GSI) SDK 호출 코드 작성
|
||||
const mockGoogleToken = 'mock_google_token_123';
|
||||
await handleSocialLogin('google', mockGoogleToken);
|
||||
};
|
||||
|
||||
const loginWithApple = async () => {
|
||||
// TODO: Sign in with Apple JS 호출 코드 작성
|
||||
const mockAppleToken = 'mock_apple_token_456';
|
||||
await handleSocialLogin('apple', mockAppleToken);
|
||||
};
|
||||
|
||||
const loginWithFacebook = async () => {
|
||||
// TODO: Facebook Login SDK 호출 코드 작성
|
||||
const mockFacebookToken = 'mock_facebook_token_789';
|
||||
await handleSocialLogin('facebook', mockFacebookToken);
|
||||
};
|
||||
|
||||
// UI 컴포넌트에 노출할 상태와 함수들만 캡슐화하여 반환
|
||||
return {
|
||||
loginWithGoogle,
|
||||
loginWithApple,
|
||||
loginWithFacebook,
|
||||
isLoading,
|
||||
error,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user