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