From 6f500bbe93f18ab424fab18162ba53d93d638ca3 Mon Sep 17 00:00:00 2001 From: Tiantian Li Date: Wed, 3 Jul 2024 16:55:06 +1000 Subject: [PATCH 1/3] feat: third party sign in Added third party account sign in functionality: - added onclick event to the social account buttons of Facebook and Google; - implemented third party login handling function that redirects to third party authentication page; - added useEffect hook for detecting third party authentication success; Resolve CP-25 --- README.md | 1 + src/app/(auth)/login/page.tsx | 28 +++++++++++++++++++++++++--- src/graphql/codegen/graphql.ts | 2 +- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f18dc1e..daa0c18 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ ``` NEXT_PUBLIC_DEV_SERVER_URL=http://localhost:3000/graphql + THIRD_PARTY_API_URL=http://localhost:3000/auth ``` ## Environment Variables diff --git a/src/app/(auth)/login/page.tsx b/src/app/(auth)/login/page.tsx index fd3bb65..f50a414 100644 --- a/src/app/(auth)/login/page.tsx +++ b/src/app/(auth)/login/page.tsx @@ -1,6 +1,6 @@ 'use client'; -import { useState } from 'react'; +import { useState, useEffect } from 'react'; import FacebookIcon from 'mdi-react/FacebookIcon'; import GooglePlusIcon from 'mdi-react/GooglePlusIcon'; import { @@ -59,6 +59,28 @@ const Login = () => { } }; + useEffect(() => { + const urlParams = new URLSearchParams(window.location.search); + const token = urlParams.get('token'); + if (token) { + if (typeof window !== 'undefined') { + localStorage.setItem(EMAIL, ''); + localStorage.setItem(AUTH_TOKEN, ''); + sessionStorage.setItem(AUTH_TOKEN, token ?? ''); + } + if (originUrl && originUrl !== '/') { + router.back(); + } else { + router.push('dashboard'); + } + } + }, [router, originUrl]); + + const handleThirdPartyLogin = (provider: string) => { + const thirdPartyApiUrl = process.env.THIRD_PARTY_API_URL; + window.location.href = `${thirdPartyApiUrl}/${provider}`; + }; + return ( @@ -82,11 +104,11 @@ const Login = () => { {/* @ts-ignore - Ignoring because of complex union types incorrectly inferred */} handleThirdPartyLogin('facebook')} > - + handleThirdPartyLogin('google')}> diff --git a/src/graphql/codegen/graphql.ts b/src/graphql/codegen/graphql.ts index d53c2b1..d7fcc0b 100644 --- a/src/graphql/codegen/graphql.ts +++ b/src/graphql/codegen/graphql.ts @@ -74,7 +74,7 @@ export type Mutation = { /** Create exchange key */ createExchangeKey: Scalars['Boolean']['output']; /** Create new user */ - createUser: Scalars['Boolean']['output']; + createUser: Scalars['String']['output']; /** Hard delete an user */ deleteUser: Scalars['Boolean']['output']; /** Hard delete an user key */ From f3e9add0e6c7a66bae850bfae5b2c8cc69dab151 Mon Sep 17 00:00:00 2001 From: Benchen997 Date: Mon, 5 Aug 2024 23:08:18 +1000 Subject: [PATCH 2/3] update Oauth redirect url env name, re-format code using prettier --- src/app/(auth)/login/page.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/(auth)/login/page.tsx b/src/app/(auth)/login/page.tsx index f50a414..07fd777 100644 --- a/src/app/(auth)/login/page.tsx +++ b/src/app/(auth)/login/page.tsx @@ -77,7 +77,7 @@ const Login = () => { }, [router, originUrl]); const handleThirdPartyLogin = (provider: string) => { - const thirdPartyApiUrl = process.env.THIRD_PARTY_API_URL; + const thirdPartyApiUrl = process.env.NEXT_PUBLIC_THIRD_PARTY_API_URL; window.location.href = `${thirdPartyApiUrl}/${provider}`; }; From eb2f033ed7f7d6eff0deac1307d003adffbcde56 Mon Sep 17 00:00:00 2001 From: Benchen997 Date: Tue, 6 Aug 2024 12:35:11 +1000 Subject: [PATCH 3/3] update reademe --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index daa0c18..4c087cc 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ ``` NEXT_PUBLIC_DEV_SERVER_URL=http://localhost:3000/graphql - THIRD_PARTY_API_URL=http://localhost:3000/auth + NEXT_PUBLIC_THIRD_PARTY_API_URL=http://localhost:3000/auth ``` ## Environment Variables