Skip to content

Commit

Permalink
Merge pull request #269 from depromeet/feature/#255
Browse files Browse the repository at this point in the history
popup option 수정
  • Loading branch information
YOOJS1205 authored Feb 12, 2024
2 parents 049b3ce + 35e7dc9 commit c8566ff
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 33 deletions.
45 changes: 28 additions & 17 deletions src/app/login/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,33 @@ const REDIRECT_URI =

export default function Page() {
useEffect(() => {
document.addEventListener('onAppleLoginSuccess', (e) => {
console.log(e);
});
// Apple 로그인 성공 이벤트 리스너 등록
const handleAppleLoginSuccess = (e: unknown) => {
console.log(e); // 성공 응답 처리
};

// Apple 로그인 실패 이벤트 리스너 등록
const handleAppleLoginFail = (e: unknown) => {
console.error(e); // 실패 응답 처리
};

document.addEventListener(
'AppleIDSignInOnSuccess',
handleAppleLoginSuccess,
);
document.addEventListener('AppleIDSignInOnFailure', handleAppleLoginFail);

// 컴포넌트 언마운트 시 이벤트 리스너 제거
return () => {
document.removeEventListener(
'AppleIDSignInOnSuccess',
handleAppleLoginSuccess,
);
document.removeEventListener(
'AppleIDSignInOnFailure',
handleAppleLoginFail,
);
};
}, []);

const { push } = useRouter();
Expand All @@ -31,20 +55,7 @@ export default function Page() {

const handleClickAppleLoginButton = async () => {
try {
const res = await window.AppleID?.auth
.signIn()
.then((response) => {
localStorage.setItem('apple_login_info', JSON.stringify(response));
const event = new CustomEvent('onAppleLoginSuccess', {
detail: response,
});
document.dispatchEvent(event);
})
.catch((error) => {
const event = new CustomEvent('onAppleLoginFail', { detail: error });
document.dispatchEvent(event);
});
console.log(res);
await window.AppleID?.auth.signIn();
} catch (error) {
console.log(error);
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/common/AppleProvider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function AppleProvider() {
redirectURI: `${process.env.NEXT_PUBLIC_SITE_DOMAIN}/login`,
state: 'origin:web',
nonce: generateNonce(16),
usePopup: false,
usePopup: true,
});
}
};
Expand Down
30 changes: 15 additions & 15 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,21 @@ export async function middleware(request: NextRequest) {
}
}

if (request.nextUrl.pathname === '/login') {
// 이미 리다이렉트된 요청인지 확인
if (request.nextUrl.searchParams.has('redirected')) {
// 이미 리다이렉트된 경우, 추가 리다이렉트를 수행하지 않음
return NextResponse.next();
} else {
// 쿼리 파라미터를 포함한 완전한 URL 구성
const redirectUrl = request.nextUrl.clone();
redirectUrl.searchParams.set('type', 'apple');
redirectUrl.searchParams.set('redirected', 'true'); // 리다이렉트 플래그 설정

// 클라이언트에게 리다이렉트 요청
return NextResponse.redirect(redirectUrl, 303);
}
}
// if (request.nextUrl.pathname === '/login') {
// // 이미 리다이렉트된 요청인지 확인
// if (request.nextUrl.searchParams.has('redirected')) {
// // 이미 리다이렉트된 경우, 추가 리다이렉트를 수행하지 않음
// return NextResponse.next();
// } else {
// // 쿼리 파라미터를 포함한 완전한 URL 구성
// const redirectUrl = request.nextUrl.clone();
// redirectUrl.searchParams.set('type', 'apple');
// redirectUrl.searchParams.set('redirected', 'true'); // 리다이렉트 플래그 설정

// // 클라이언트에게 리다이렉트 요청
// return NextResponse.redirect(redirectUrl, 303);
// }
// }
}

export const config = {
Expand Down

0 comments on commit c8566ff

Please sign in to comment.