mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-08 14:28:20 +00:00
show toast when oauth login error
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import jwt_decode from 'jwt-decode';
|
import jwt_decode from 'jwt-decode';
|
||||||
|
|
||||||
|
import { useNotificationContext } from '@app/components/context/Notifications/NotificationProvider';
|
||||||
import SecurityClient, { PROVIDER_AUTH_TOKEN_KEY } from '@app/components/utilities/SecurityClient';
|
import SecurityClient, { PROVIDER_AUTH_TOKEN_KEY } from '@app/components/utilities/SecurityClient';
|
||||||
|
|
||||||
export const useProviderAuth = () => {
|
export const useProviderAuth = () => {
|
||||||
@@ -8,12 +9,19 @@ export const useProviderAuth = () => {
|
|||||||
const [userId, setUserId] = useState<string>('');
|
const [userId, setUserId] = useState<string>('');
|
||||||
const [providerAuthToken, setProviderAuthToken] = useState<string>('');
|
const [providerAuthToken, setProviderAuthToken] = useState<string>('');
|
||||||
const [isProviderUserCompleted, setIsProviderUserCompleted] = useState<boolean>();
|
const [isProviderUserCompleted, setIsProviderUserCompleted] = useState<boolean>();
|
||||||
|
const { createNotification } = useNotificationContext();
|
||||||
|
const AUTH_ERROR_KEY = 'PROVIDER_AUTH_ERROR'
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
SecurityClient.setProviderAuthToken('')
|
SecurityClient.setProviderAuthToken('')
|
||||||
|
window.localStorage.removeItem(AUTH_ERROR_KEY);
|
||||||
|
|
||||||
const handleStorageChange = (event: StorageEvent) => {
|
const handleStorageChange = (event: StorageEvent) => {
|
||||||
if (event.storageArea === localStorage && event.key === PROVIDER_AUTH_TOKEN_KEY) {
|
if (event.storageArea !== localStorage) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.key === PROVIDER_AUTH_TOKEN_KEY) {
|
||||||
if (event.newValue) {
|
if (event.newValue) {
|
||||||
const token = event.newValue;
|
const token = event.newValue;
|
||||||
const {
|
const {
|
||||||
@@ -33,6 +41,18 @@ export const useProviderAuth = () => {
|
|||||||
}
|
}
|
||||||
setProviderAuthToken(event.newValue || '');
|
setProviderAuthToken(event.newValue || '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (event.key === AUTH_ERROR_KEY) {
|
||||||
|
if (event.newValue) {
|
||||||
|
createNotification({
|
||||||
|
text: 'An error has occured during login.',
|
||||||
|
type: 'error',
|
||||||
|
timeoutMs: 6000,
|
||||||
|
})
|
||||||
|
|
||||||
|
window.localStorage.removeItem(AUTH_ERROR_KEY);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
window.addEventListener('storage', handleStorageChange);
|
window.addEventListener('storage', handleStorageChange);
|
||||||
|
|||||||
@@ -57,9 +57,11 @@ const App = ({ Component, pageProps, ...appProps }: NextAppProp): JSX.Element =>
|
|||||||
) {
|
) {
|
||||||
return (
|
return (
|
||||||
<QueryClientProvider client={queryClient}>
|
<QueryClientProvider client={queryClient}>
|
||||||
<AuthProvider>
|
<NotificationProvider>
|
||||||
<Component {...pageProps} />
|
<AuthProvider>
|
||||||
</AuthProvider>
|
<Component {...pageProps} />
|
||||||
|
</AuthProvider>
|
||||||
|
</NotificationProvider>
|
||||||
</QueryClientProvider>
|
</QueryClientProvider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
|
import { useEffect } from "react";
|
||||||
|
|
||||||
export default function LoginProviderError() {
|
export default function LoginProviderError() {
|
||||||
return (
|
useEffect(() => {
|
||||||
<div className="bg-gradient-to-tr from-bunker-500 to-bunker-800 h-screen flex flex-col justify-center pb-28 px-6 items-center">
|
window.localStorage.setItem('PROVIDER_AUTH_ERROR', 'err');
|
||||||
<span className="text-white text-xl" >Oops! An error has occured.</span>
|
window.close();
|
||||||
</div>
|
}, [])
|
||||||
)
|
|
||||||
|
return <div />
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user