diff --git a/README.md b/README.md index f18dc1e..4c087cc 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ ``` NEXT_PUBLIC_DEV_SERVER_URL=http://localhost:3000/graphql + NEXT_PUBLIC_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..07fd777 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.NEXT_PUBLIC_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 */