This repository has been archived by the owner on Dec 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add auth alert when front gets a 401 or 403
- Loading branch information
1 parent
e714f9c
commit 14782da
Showing
6 changed files
with
74 additions
and
11 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { ExclamationTriangleIcon } from '@heroicons/react/24/solid' | ||
|
||
function AuthAlert() { | ||
const redirectUrl = `${window.location.protocol}//${window.location.host}` | ||
const loginUrl = `${process.env.REACT_APP_ERGOMAKE_API}/v2/auth/login?redirectUrl=${redirectUrl}` | ||
|
||
return ( | ||
<div className="bg-yellow-100/50 text-gray-300 p-4 border-b border-b-gray-200 dark:border-t dark:border-yellow-400 flex space-x-2 items-center justify-center font-bold"> | ||
<ExclamationTriangleIcon className="w-6 h-6 inline-block text-yellow-500 dark:text-yellow-400" /> | ||
<span className="text-gray-600 dark:text-gray-300"> | ||
You're no longer authenticated.{' '} | ||
<a | ||
className="text-primary-500 hover:underline hover:text-primary-400 dark:text-white" | ||
href={loginUrl} | ||
> | ||
Sign in with GitHub. | ||
</a> | ||
</span> | ||
</div> | ||
) | ||
} | ||
|
||
export default AuthAlert |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { createContext, useContext, useState } from 'react' | ||
|
||
type UseAuthError = [boolean, (error: boolean) => void] | ||
export const AuthErrorContext = createContext<UseAuthError>([ | ||
false, | ||
(_: boolean) => {}, | ||
]) | ||
|
||
export const useAuthErrorProvider = (): UseAuthError => { | ||
return useState(false) | ||
} | ||
|
||
export function AuthErrorProvider({ children }: { children: React.ReactNode }) { | ||
const themeValue = useAuthErrorProvider() | ||
|
||
return ( | ||
<AuthErrorContext.Provider value={themeValue}> | ||
{children} | ||
</AuthErrorContext.Provider> | ||
) | ||
} | ||
|
||
export const useAuthError = () => useContext(AuthErrorContext) |
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