-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSocialGoogle.tsx
More file actions
84 lines (76 loc) · 1.93 KB
/
SocialGoogle.tsx
File metadata and controls
84 lines (76 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import React, { Suspense, useEffect, useState } from 'react';
import Image from 'next/image';
import styled from 'styled-components';
import { useSearchParams } from 'next/navigation';
import { setLetterUrl } from '@/utils/storage';
import Loader, { LoaderContainer } from '../common/Loader';
const SocialGoogle = () => {
const searchParams = useSearchParams();
const url = searchParams.get('url');
const [absoluteUrl, setabsoluteUrl] = useState('');
useEffect(() => {
if (typeof window !== 'undefined') {
setabsoluteUrl(
window.location.protocol +
'//' +
window.location.host +
'/login/auth?type=google'
);
}
}, []);
const handleLogin = () => {
if (url) {
setLetterUrl(url);
}
const GOOGLE_CLIENT_ID = process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID;
const scope = 'openid profile email';
const authUrl = [
'https://accounts.google.com/o/oauth2/v2/auth',
`?client_id=${GOOGLE_CLIENT_ID}`,
`&redirect_uri=${encodeURIComponent(absoluteUrl)}`,
`&response_type=code`,
`&scope=${encodeURIComponent(scope)}`,
`&access_type=offline`,
`&prompt=consent`
].join('');
window.location.href = authUrl;
};
return (
<SocialLoginBox onClick={handleLogin}>
<StyledImage
src="/assets/icons/ic_google.svg"
width={33}
height={33}
alt="google"
/>
</SocialLoginBox>
);
};
export default function SocialGooglePaging() {
return (
<Suspense
fallback={
<LoaderContainer>
<Loader />
</LoaderContainer>
}
>
<SocialGoogle />
</Suspense>
);
}
const SocialLoginBox = styled.div`
display: flex;
box-sizing: border-box;
width: 100%;
cursor: pointer;
display: flex;
justify-content: center;
align-items: center;
`;
const StyledImage = styled(Image)`
width: 100%;
height: 100%;
padding: 0 16px;
object-fit: contain;
`;