mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 21:06:42 +07:00
showing needs_register dialog
This commit is contained in:
parent
441a0824cc
commit
ff8ecba6db
6 changed files with 46 additions and 24 deletions
|
@ -140,7 +140,7 @@ export const apiLoginWithSocial = ({
|
|||
password?: string;
|
||||
}): Promise<IResultWithStatus<{
|
||||
token: string;
|
||||
needs_login: boolean;
|
||||
needs_register: boolean;
|
||||
}>> =>
|
||||
api
|
||||
.post(API.USER.LOGIN_WITH_SOCIAL, { token, username, password })
|
||||
|
|
|
@ -50,7 +50,7 @@ import {
|
|||
selectAuthUser,
|
||||
selectToken,
|
||||
} from './selectors';
|
||||
import { IMessageNotification, IResultWithStatus, Unwrap } from '../types';
|
||||
import { IMessageNotification, IResultWithStatus, OAUTH_EVENT_TYPES, Unwrap } from '../types';
|
||||
import { IAuthState, IUser } from './types';
|
||||
import { REHYDRATE, RehydrateAction } from 'redux-persist';
|
||||
import { selectModal } from '~/redux/modal/selectors';
|
||||
|
@ -459,6 +459,11 @@ function* loginWithSocial({ token }: ReturnType<typeof authLoginWithSocial>) {
|
|||
error,
|
||||
}: Unwrap<ReturnType<typeof apiLoginWithSocial>> = yield call(apiLoginWithSocial, { token });
|
||||
|
||||
if (data?.needs_register) {
|
||||
yield put(modalShowDialog(DIALOGS.LOGIN_SOCIAL_REGISTER));
|
||||
return;
|
||||
}
|
||||
|
||||
if (error) {
|
||||
throw new Error(error);
|
||||
}
|
||||
|
@ -475,13 +480,15 @@ function* loginWithSocial({ token }: ReturnType<typeof authLoginWithSocial>) {
|
|||
}
|
||||
|
||||
function* gotOauthEvent({ event }: ReturnType<typeof authGotOauthEvent>) {
|
||||
if (!event?.data?.type) return;
|
||||
if (!event?.type) return;
|
||||
|
||||
switch (event.type) {
|
||||
case OAUTH_EVENT_TYPES.OAUTH_PROCESSED:
|
||||
return yield put(authLoginWithSocial(event?.payload?.token));
|
||||
|
||||
case OAUTH_EVENT_TYPES.OAUTH_ERROR:
|
||||
return yield put(userSetLoginError(event?.payload?.error));
|
||||
|
||||
switch (event?.data?.type) {
|
||||
case 'oauth_processed':
|
||||
return put(authLoginWithSocial(event?.data?.payload?.token));
|
||||
case 'oauth_error':
|
||||
return put(userSetLoginError(event?.data?.payload?.error));
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ export const DIALOGS = {
|
|||
EDITOR_VIDEO: 'EDITOR_VIDEO',
|
||||
EDITOR_AUDIO: 'EDITOR_AUDIO',
|
||||
LOGIN: 'LOGIN',
|
||||
LOGIN_SOCIAL_REGISTER: 'LOGIN_REGISTER',
|
||||
LOGIN_SOCIAL_REGISTER: 'LOGIN_SOCIAL_REGISTER',
|
||||
LOADING: 'LOADING',
|
||||
PROFILE: 'PROFILE',
|
||||
RESTORE_REQUEST: 'RESTORE_REQUEST',
|
||||
|
|
|
@ -207,13 +207,16 @@ export interface IEmbed {
|
|||
};
|
||||
}
|
||||
|
||||
export type IOAuthEvent = MessageEvent & {
|
||||
data: {
|
||||
type: 'oauth_processed' | 'oauth_error';
|
||||
payload: {
|
||||
token: string;
|
||||
error: string;
|
||||
needs_register: boolean;
|
||||
};
|
||||
export const OAUTH_EVENT_TYPES = {
|
||||
OAUTH_PROCESSED: 'oauth_processed',
|
||||
OAUTH_ERROR: 'oauth_error',
|
||||
};
|
||||
|
||||
export type IOAuthEvent = {
|
||||
type: typeof OAUTH_EVENT_TYPES[keyof typeof OAUTH_EVENT_TYPES];
|
||||
payload: {
|
||||
token: string;
|
||||
error: string;
|
||||
needs_register: boolean;
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue