Client - add account confirmation (WIP)
This commit is contained in:
@ -22,7 +22,7 @@ import {
|
||||
ILoginOrRegisterData,
|
||||
IUserAccountPayload,
|
||||
IUserDeletionPayload,
|
||||
IUserEmailUpdatePayload,
|
||||
IUserAccountUpdatePayload,
|
||||
IUserPasswordPayload,
|
||||
IUserPasswordResetPayload,
|
||||
IUserPayload,
|
||||
@ -63,9 +63,32 @@ export const actions: ActionTree<IAuthUserState, IRootState> &
|
||||
context.dispatch(AUTH_USER_STORE.ACTIONS.GET_USER_PROFILE)
|
||||
}
|
||||
},
|
||||
[AUTH_USER_STORE.ACTIONS.CONFIRM_ACCOUNT](
|
||||
context: ActionContext<IAuthUserState, IRootState>,
|
||||
payload: IUserAccountUpdatePayload
|
||||
): void {
|
||||
context.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES)
|
||||
api
|
||||
.post('auth/account/confirm', { token: payload.token })
|
||||
.then((res) => {
|
||||
if (res.data.status === 'success') {
|
||||
const token = res.data.auth_token
|
||||
window.localStorage.setItem('authToken', token)
|
||||
context.commit(AUTH_USER_STORE.MUTATIONS.UPDATE_AUTH_TOKEN, token)
|
||||
context
|
||||
.dispatch(AUTH_USER_STORE.ACTIONS.GET_USER_PROFILE)
|
||||
.then(() => router.push('/'))
|
||||
} else {
|
||||
handleError(context, null)
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
handleError(context, error)
|
||||
})
|
||||
},
|
||||
[AUTH_USER_STORE.ACTIONS.CONFIRM_EMAIL](
|
||||
context: ActionContext<IAuthUserState, IRootState>,
|
||||
payload: IUserEmailUpdatePayload
|
||||
payload: IUserAccountUpdatePayload
|
||||
): void {
|
||||
context.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES)
|
||||
context.commit(AUTH_USER_STORE.MUTATIONS.UPDATE_IS_SUCCESS, false)
|
||||
@ -125,20 +148,35 @@ export const actions: ActionTree<IAuthUserState, IRootState> &
|
||||
data: ILoginOrRegisterData
|
||||
): void {
|
||||
context.commit(ROOT_STORE.MUTATIONS.EMPTY_ERROR_MESSAGES)
|
||||
context.commit(
|
||||
AUTH_USER_STORE.MUTATIONS.UPDATE_IS_REGISTRATION_SUCCESS,
|
||||
false
|
||||
)
|
||||
api
|
||||
.post(`/auth/${data.actionType}`, data.formData)
|
||||
.then((res) => {
|
||||
if (res.data.status === 'success') {
|
||||
const token = res.data.auth_token
|
||||
window.localStorage.setItem('authToken', token)
|
||||
context.commit(AUTH_USER_STORE.MUTATIONS.UPDATE_AUTH_TOKEN, token)
|
||||
context
|
||||
.dispatch(AUTH_USER_STORE.ACTIONS.GET_USER_PROFILE)
|
||||
.then(() =>
|
||||
router.push(
|
||||
typeof data.redirectUrl === 'string' ? data.redirectUrl : '/'
|
||||
if (data.actionType === 'login') {
|
||||
const token = res.data.auth_token
|
||||
window.localStorage.setItem('authToken', token)
|
||||
context.commit(AUTH_USER_STORE.MUTATIONS.UPDATE_AUTH_TOKEN, token)
|
||||
context
|
||||
.dispatch(AUTH_USER_STORE.ACTIONS.GET_USER_PROFILE)
|
||||
.then(() =>
|
||||
router.push(
|
||||
typeof data.redirectUrl === 'string' ? data.redirectUrl : '/'
|
||||
)
|
||||
)
|
||||
)
|
||||
} else {
|
||||
router
|
||||
.push('/login')
|
||||
.then(() =>
|
||||
context.commit(
|
||||
AUTH_USER_STORE.MUTATIONS.UPDATE_IS_REGISTRATION_SUCCESS,
|
||||
true
|
||||
)
|
||||
)
|
||||
}
|
||||
} else {
|
||||
handleError(context, null)
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
export enum AuthUserActions {
|
||||
CHECK_AUTH_USER = 'CHECK_AUTH_USER',
|
||||
CONFIRM_ACCOUNT = 'CONFIRM_ACCOUNT',
|
||||
CONFIRM_EMAIL = 'CONFIRM_EMAIL',
|
||||
DELETE_ACCOUNT = 'DELETE_ACCOUNT',
|
||||
DELETE_PICTURE = 'DELETE_PICTURE',
|
||||
@ -22,6 +23,7 @@ export enum AuthUserGetters {
|
||||
IS_ADMIN = 'IS_ADMIN',
|
||||
IS_AUTHENTICATED = 'IS_AUTHENTICATED',
|
||||
IS_SUCCESS = 'IS_SUCCESS',
|
||||
IS_REGISTRATION_SUCCESS = 'IS_REGISTRATION_SUCCESS',
|
||||
USER_LOADING = 'USER_LOADING',
|
||||
}
|
||||
|
||||
@ -30,5 +32,6 @@ export enum AuthUserMutations {
|
||||
UPDATE_AUTH_TOKEN = 'UPDATE_AUTH_TOKEN',
|
||||
UPDATE_AUTH_USER_PROFILE = 'UPDATE_AUTH_USER_PROFILE',
|
||||
UPDATE_IS_SUCCESS = 'UPDATE_USER_IS_SUCCESS',
|
||||
UPDATE_IS_REGISTRATION_SUCCESS = 'UPDATE_IS_REGISTRATION_SUCCESS',
|
||||
UPDATE_USER_LOADING = 'UPDATE_USER_LOADING',
|
||||
}
|
||||
|
@ -21,6 +21,11 @@ export const getters: GetterTree<IAuthUserState, IRootState> &
|
||||
[AUTH_USER_STORE.GETTERS.IS_ADMIN]: (state: IAuthUserState) => {
|
||||
return state.authUserProfile && state.authUserProfile.admin
|
||||
},
|
||||
[AUTH_USER_STORE.GETTERS.IS_REGISTRATION_SUCCESS]: (
|
||||
state: IAuthUserState
|
||||
) => {
|
||||
return state.isRegistrationSuccess
|
||||
},
|
||||
[AUTH_USER_STORE.GETTERS.IS_SUCCESS]: (state: IAuthUserState) => {
|
||||
return state.isSuccess
|
||||
},
|
||||
|
@ -24,6 +24,12 @@ export const mutations: MutationTree<IAuthUserState> & TAuthUserMutations = {
|
||||
) {
|
||||
state.authUserProfile = authUserProfile
|
||||
},
|
||||
[AUTH_USER_STORE.MUTATIONS.UPDATE_IS_REGISTRATION_SUCCESS](
|
||||
state: IAuthUserState,
|
||||
isRegistrationSuccess: boolean
|
||||
) {
|
||||
state.isRegistrationSuccess = isRegistrationSuccess
|
||||
},
|
||||
[AUTH_USER_STORE.MUTATIONS.UPDATE_IS_SUCCESS](
|
||||
state: IAuthUserState,
|
||||
isSuccess: boolean
|
||||
|
@ -5,5 +5,6 @@ export const authUserState: IAuthUserState = {
|
||||
authToken: null,
|
||||
authUserProfile: <IAuthUserProfile>{},
|
||||
isSuccess: false,
|
||||
isRegistrationSuccess: false,
|
||||
loading: false,
|
||||
}
|
||||
|
@ -18,12 +18,13 @@ import {
|
||||
IUserPreferencesPayload,
|
||||
IUserSportPreferencesPayload,
|
||||
IUserAccountPayload,
|
||||
IUserEmailUpdatePayload,
|
||||
IUserAccountUpdatePayload,
|
||||
} from '@/types/user'
|
||||
|
||||
export interface IAuthUserState {
|
||||
authToken: string | null
|
||||
authUserProfile: IAuthUserProfile
|
||||
isRegistrationSuccess: boolean
|
||||
isSuccess: boolean
|
||||
loading: boolean
|
||||
}
|
||||
@ -33,9 +34,14 @@ export interface IAuthUserActions {
|
||||
context: ActionContext<IAuthUserState, IRootState>
|
||||
): void
|
||||
|
||||
[AUTH_USER_STORE.ACTIONS.CONFIRM_ACCOUNT](
|
||||
context: ActionContext<IAuthUserState, IRootState>,
|
||||
payload: IUserAccountUpdatePayload
|
||||
): void
|
||||
|
||||
[AUTH_USER_STORE.ACTIONS.CONFIRM_EMAIL](
|
||||
context: ActionContext<IAuthUserState, IRootState>,
|
||||
payload: IUserEmailUpdatePayload
|
||||
payload: IUserAccountUpdatePayload
|
||||
): void
|
||||
|
||||
[AUTH_USER_STORE.ACTIONS.GET_USER_PROFILE](
|
||||
@ -112,6 +118,10 @@ export interface IAuthUserGetters {
|
||||
|
||||
[AUTH_USER_STORE.GETTERS.IS_AUTHENTICATED](state: IAuthUserState): boolean
|
||||
|
||||
[AUTH_USER_STORE.GETTERS.IS_REGISTRATION_SUCCESS](
|
||||
state: IAuthUserState
|
||||
): boolean
|
||||
|
||||
[AUTH_USER_STORE.GETTERS.IS_SUCCESS](state: IAuthUserState): boolean
|
||||
|
||||
[AUTH_USER_STORE.GETTERS.USER_LOADING](state: IAuthUserState): boolean
|
||||
@ -135,6 +145,10 @@ export type TAuthUserMutations<S = IAuthUserState> = {
|
||||
state: S,
|
||||
loading: boolean
|
||||
): void
|
||||
[AUTH_USER_STORE.MUTATIONS.UPDATE_IS_REGISTRATION_SUCCESS](
|
||||
state: S,
|
||||
loading: boolean
|
||||
): void
|
||||
}
|
||||
|
||||
export type TAuthUserStoreModule<S = IAuthUserState> = Omit<
|
||||
|
Reference in New Issue
Block a user