|
| 1 | +import React, { Suspense, useEffect, useState } from 'react'; |
| 2 | +import Image from 'next/image'; |
| 3 | +import styled from 'styled-components'; |
| 4 | +import { useRouter, useSearchParams } from 'next/navigation'; |
| 5 | +import { useRecoilState } from 'recoil'; |
| 6 | +import { accessState } from '@/recoil/accessStore'; |
| 7 | +import { getAccessToken, setLetterUrl } from '@/utils/storage'; |
| 8 | +import Loader, { LoaderContainer } from '../common/Loader'; |
| 9 | + |
| 10 | +const SocialGoogle = () => { |
| 11 | + const searchParams = useSearchParams(); |
| 12 | + const url = searchParams.get('url'); |
| 13 | + const REST_API_KEY = process.env.NEXT_PUBLIC_REST_API_KEY; |
| 14 | + const GOOGLE_URL = '/login/google'; |
| 15 | + const [absoluteUrl, setabsoluteUrl] = useState(''); |
| 16 | + |
| 17 | + useEffect(() => { |
| 18 | + if (typeof window !== 'undefined') { |
| 19 | + setabsoluteUrl( |
| 20 | + window.location.protocol + '//' + window.location.host + '/login/kakao' |
| 21 | + ); |
| 22 | + } |
| 23 | + }, []); |
| 24 | + |
| 25 | + const handleLogin = () => { |
| 26 | + //이때 localStorage에 저장된 accessToken이 만료되었는지 확인해야함. |
| 27 | + // if (accessToken) { |
| 28 | + // if (url) { |
| 29 | + // router.push(`/verify?url=${url}`); |
| 30 | + // } else { |
| 31 | + // router.push("/"); |
| 32 | + // } |
| 33 | + // setAccessToken(accessToken); |
| 34 | + // } else { |
| 35 | + //받은 편지를 통해 들어올 경우 url를 저장한다. |
| 36 | + if (url) { |
| 37 | + setLetterUrl(url); |
| 38 | + } |
| 39 | + window.location.href = GOOGLE_URL; |
| 40 | + }; |
| 41 | + |
| 42 | + return ( |
| 43 | + <SocialLoginBox onClick={handleLogin}> |
| 44 | + <StyledImage |
| 45 | + src="/assets/icons/ic_google.svg" |
| 46 | + width={33} |
| 47 | + height={33} |
| 48 | + alt="google" |
| 49 | + /> |
| 50 | + </SocialLoginBox> |
| 51 | + ); |
| 52 | +}; |
| 53 | + |
| 54 | +export default function SocialGooglePaging() { |
| 55 | + return ( |
| 56 | + <Suspense |
| 57 | + fallback={ |
| 58 | + <LoaderContainer> |
| 59 | + <Loader /> |
| 60 | + </LoaderContainer> |
| 61 | + } |
| 62 | + > |
| 63 | + <SocialGoogle /> |
| 64 | + </Suspense> |
| 65 | + ); |
| 66 | +} |
| 67 | + |
| 68 | +const SocialLoginBox = styled.div` |
| 69 | + display: flex; |
| 70 | + box-sizing: border-box; |
| 71 | + width: 100%; |
| 72 | + cursor: pointer; |
| 73 | + display: flex; |
| 74 | + justify-content: center; |
| 75 | + align-items: center; |
| 76 | +`; |
| 77 | + |
| 78 | +const StyledImage = styled(Image)` |
| 79 | + width: 100%; |
| 80 | + height: 100%; |
| 81 | + padding: 0 16px; |
| 82 | + object-fit: contain; |
| 83 | +`; |
0 commit comments