Skip to content

Commit

Permalink
feat: implement siginin with google
Browse files Browse the repository at this point in the history
  • Loading branch information
solufa committed Sep 13, 2024
1 parent a27fbc6 commit 152dc88
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ ARG NEXT_PUBLIC_API_BASE_PATH=/api
ARG NEXT_PUBLIC_COGNITO_POOL_ENDPOINT
ARG NEXT_PUBLIC_COGNITO_USER_POOL_ID
ARG NEXT_PUBLIC_COGNITO_USER_POOL_CLIENT_ID
ARG NEXT_PUBLIC_OAUTH_DOMAIN
ARG DATABASE_URL

ENV NEXT_PUBLIC_API_BASE_PATH=$NEXT_PUBLIC_API_BASE_PATH
Expand Down
1 change: 1 addition & 0 deletions client/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ NEXT_PUBLIC_SERVER_PORT=31577
NEXT_PUBLIC_COGNITO_POOL_ENDPOINT=http://localhost:5050
NEXT_PUBLIC_COGNITO_USER_POOL_ID=ap-northeast-1_frourio
NEXT_PUBLIC_COGNITO_USER_POOL_CLIENT_ID=catapult
NEXT_PUBLIC_OAUTH_DOMAIN=XXXXXXXXXXXX.auth.ap-northeast-1.amazoncognito.com
15 changes: 15 additions & 0 deletions client/pages/_app.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import dynamic from 'next/dynamic';
import Head from 'next/head';
import { useEffect } from 'react';
import 'styles/globals.css';
import { pagesPath } from 'utils/$path';
import {
NEXT_PUBLIC_COGNITO_POOL_ENDPOINT,
NEXT_PUBLIC_COGNITO_USER_POOL_CLIENT_ID,
NEXT_PUBLIC_COGNITO_USER_POOL_ID,
NEXT_PUBLIC_OAUTH_DOMAIN,
} from 'utils/envValues';
import '../styles/globals.css';

Expand All @@ -26,6 +28,19 @@ function MyApp({ Component, pageProps }: AppProps) {
userPoolEndpoint: NEXT_PUBLIC_COGNITO_POOL_ENDPOINT,
userPoolId: NEXT_PUBLIC_COGNITO_USER_POOL_ID,
userPoolClientId: NEXT_PUBLIC_COGNITO_USER_POOL_CLIENT_ID,
loginWith:
NEXT_PUBLIC_OAUTH_DOMAIN === undefined
? undefined
: {
email: true,
oauth: {
domain: NEXT_PUBLIC_OAUTH_DOMAIN,
scopes: ['openid'],
redirectSignIn: [`${location.origin}${pagesPath.login}`],
redirectSignOut: [`${location.origin}${pagesPath.login}`],
responseType: 'code',
},
},
},
},
});
Expand Down
2 changes: 2 additions & 0 deletions client/pages/login/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useUser } from 'hooks/useUser';
import { useRouter } from 'next/router';
import { useEffect } from 'react';
import { pagesPath, staticPath } from 'utils/$path';
import { NEXT_PUBLIC_OAUTH_DOMAIN } from 'utils/envValues';
import styles from './index.module.css';

const Login = () => {
Expand All @@ -28,6 +29,7 @@ const Login = () => {
<Spacer axis="y" size={36} />
<Authenticator
signUpAttributes={['email']}
socialProviders={NEXT_PUBLIC_OAUTH_DOMAIN === undefined ? undefined : ['google']}
services={{
handleSignUp: (input) =>
signUp({
Expand Down
2 changes: 2 additions & 0 deletions client/utils/envValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ const NEXT_PUBLIC_COGNITO_USER_POOL_CLIENT_ID = z
const NEXT_PUBLIC_COGNITO_POOL_ENDPOINT = z
.string()
.parse(process.env.NEXT_PUBLIC_COGNITO_POOL_ENDPOINT);
const NEXT_PUBLIC_OAUTH_DOMAIN = z.string().optional().parse(process.env.NEXT_PUBLIC_OAUTH_DOMAIN);

export {
NEXT_PUBLIC_API_BASE_PATH,
NEXT_PUBLIC_COGNITO_POOL_ENDPOINT,
NEXT_PUBLIC_COGNITO_USER_POOL_CLIENT_ID,
NEXT_PUBLIC_COGNITO_USER_POOL_ID,
NEXT_PUBLIC_OAUTH_DOMAIN,
};

0 comments on commit 152dc88

Please sign in to comment.