mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-24 20:36:40 +07:00
fixed error handling on oauth
This commit is contained in:
parent
35fd30daab
commit
f8bdd1a47a
2 changed files with 11 additions and 6 deletions
|
@ -1,14 +1,14 @@
|
|||
import { useEffect } from 'react';
|
||||
|
||||
import { EventMessageType } from '~/constants/events';
|
||||
import { Dialog } from '~/constants/modal';
|
||||
import { useAuth } from '~/hooks/auth/useAuth';
|
||||
import { useOAuth } from '~/hooks/auth/useOAuth';
|
||||
import { useModal } from '~/hooks/modal/useModal';
|
||||
import { includes, path, values } from '~/utils/ramda';
|
||||
import { showToastError } from '~/utils/toast';
|
||||
|
||||
/** reacts to events passed by window.postMessage */
|
||||
export const useMessageEventReactions = () => {
|
||||
export const useOauthEventListeners = () => {
|
||||
const { loginWithSocial, createSocialAccount, attachAccount } = useOAuth();
|
||||
const { showModal } = useModal();
|
||||
const { isUser } = useAuth();
|
||||
|
@ -25,7 +25,6 @@ export const useMessageEventReactions = () => {
|
|||
|
||||
switch (type) {
|
||||
case EventMessageType.OAuthLogin:
|
||||
// TODO: do we really need it?
|
||||
loginWithSocial(path(['data', 'payload', 'token'], event));
|
||||
break;
|
||||
case EventMessageType.OAuthProcessed:
|
||||
|
@ -35,6 +34,12 @@ export const useMessageEventReactions = () => {
|
|||
void createSocialAccount(path(['data', 'payload', 'token'], event));
|
||||
}
|
||||
break;
|
||||
case EventMessageType.OAuthError:
|
||||
const message = path(['data', 'payload', 'error'], event);
|
||||
if (message && typeof message === 'string') {
|
||||
showToastError(message);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
console.log('unknown message', event.data);
|
||||
}
|
|
@ -4,7 +4,7 @@ import { observer } from 'mobx-react-lite';
|
|||
|
||||
import { EMPTY_USER } from '~/constants/auth';
|
||||
import { useAuth } from '~/hooks/auth/useAuth';
|
||||
import { useMessageEventReactions } from '~/hooks/auth/useMessageEventReactions';
|
||||
import { useOauthEventListeners } from '~/hooks/auth/useOauthEventListeners';
|
||||
import { useRestorePasswordRedirect } from '~/hooks/auth/useRestorePasswordRedirect';
|
||||
import { useSessionCookie } from '~/hooks/auth/useSessionCookie';
|
||||
|
||||
|
@ -14,7 +14,7 @@ const AuthContext = createContext<AuthProviderContextType>({
|
|||
user: EMPTY_USER,
|
||||
isUser: false,
|
||||
isTester: false,
|
||||
setIsTester: isTester => isTester,
|
||||
setIsTester: (isTester) => isTester,
|
||||
logout: () => {},
|
||||
login: async () => EMPTY_USER,
|
||||
setToken: () => {},
|
||||
|
@ -23,7 +23,7 @@ const AuthContext = createContext<AuthProviderContextType>({
|
|||
export const AuthProvider: FC = observer(({ children }) => {
|
||||
const value = useAuth();
|
||||
|
||||
useMessageEventReactions();
|
||||
useOauthEventListeners();
|
||||
useRestorePasswordRedirect();
|
||||
useSessionCookie();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue