-
Notifications
You must be signed in to change notification settings - Fork 383
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(toolkit): use correct hook for fetching auth code (#457)
* fix(toolkit): use correct hook for fetching auth code * fix(toolkit): use correct hook for fetching auth code * fix(toolkit): fix next issue
- Loading branch information
Showing
6 changed files
with
97 additions
and
71 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
src/interfaces/coral_web/src/app/(auth)/auth/[strategy]/CompleteOauth.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
'use client'; | ||
|
||
import { useParams, useRouter, useSearchParams } from 'next/navigation'; | ||
import { useEffect } from 'react'; | ||
|
||
import { Text } from '@/components/Shared'; | ||
import { useAuthConfig } from '@/hooks/authConfig'; | ||
import { useSession } from '@/hooks/session'; | ||
import { getQueryString } from '@/utils'; | ||
|
||
/** | ||
* @description This page handles callbacks from OAuth providers and forwards the request to the backend. | ||
*/ | ||
const CompleteOauth: React.FC = () => { | ||
const router = useRouter(); | ||
const params = useParams(); | ||
const search = useSearchParams(); | ||
|
||
const { oidcSSOMutation, googleSSOMutation } = useSession(); | ||
const redirect = getQueryString(search.get('redirect_uri')); | ||
const code = getQueryString(search.get('code')); | ||
const { loginStrategies: ssoLogins } = useAuthConfig(); | ||
|
||
const loginType = ssoLogins.find( | ||
(login) => encodeURIComponent(login.strategy.toLowerCase()) == params.strategy | ||
); | ||
|
||
useEffect(() => { | ||
if (!loginType || !code) { | ||
return; | ||
} | ||
|
||
if (loginType.strategy.toLowerCase() === 'google') { | ||
googleSSOMutation.mutate( | ||
{ | ||
code, | ||
}, | ||
{ | ||
onSuccess: () => { | ||
router.push(redirect || '/'); | ||
}, | ||
onError: () => { | ||
router.push('/login'); | ||
}, | ||
} | ||
); | ||
return; | ||
} | ||
|
||
oidcSSOMutation.mutate( | ||
{ | ||
code, | ||
strategy: loginType.strategy, | ||
}, | ||
{ | ||
onSuccess: () => { | ||
router.push(redirect || '/'); | ||
}, | ||
onError: () => { | ||
router.push('/login'); | ||
}, | ||
} | ||
); | ||
}, [loginType]); | ||
|
||
return ( | ||
<div className="flex flex-col items-center justify-center"> | ||
<Text as="h1" styleAs="h3"> | ||
Logging in | ||
</Text> | ||
</div> | ||
); | ||
}; | ||
|
||
export default CompleteOauth; |
69 changes: 5 additions & 64 deletions
69
src/interfaces/coral_web/src/app/(auth)/auth/[strategy]/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters