|
|
@ -31,6 +31,7 @@ export enum Action { |
|
|
|
AuthLogin = "AUTH_LOGIN", |
|
|
|
AuthForget = "AUHT_FORGET", |
|
|
|
AuthLoad = "AUTH_LOAD", |
|
|
|
AuthVerify = "AUTH_VERIFY", |
|
|
|
|
|
|
|
// Movies Methods
|
|
|
|
ActiveMovieRequests = "ACTIVE_MOVIE_REQUESTS", |
|
|
@ -45,6 +46,7 @@ export enum Action { |
|
|
|
*/ |
|
|
|
export type ActionsTypes = { |
|
|
|
// RESTful Generics
|
|
|
|
// @TODO These shouldn't be actions as they pollute the logs
|
|
|
|
[Action.Fetch] : (payload: IGetPayload) => Promise<any>, |
|
|
|
[Action.Get] : (payload: IGetPayload) => Promise<any>, |
|
|
|
[Action.Post] : (payload: IPostPayload) => Promise<any>, |
|
|
@ -55,7 +57,8 @@ export type ActionsTypes = { |
|
|
|
[Action.AuthRegister]: (payload: IRegisterPayload) => Promise<IFormErrors|null>, |
|
|
|
[Action.AuthLogin] : (payload: ILoginPayload) => Promise<IFormErrors|null>, |
|
|
|
[Action.AuthForget] : () => void, |
|
|
|
[Action.AuthLoad] : () => boolean, |
|
|
|
[Action.AuthLoad] : () => void, |
|
|
|
[Action.AuthVerify] : () => void, |
|
|
|
|
|
|
|
// Movie Methods
|
|
|
|
[Action.ActiveMovieRequests]: () => Promise<[number, IApiDataResponse<IMovie[]>]>, |
|
|
@ -184,7 +187,7 @@ export const actions: Actions<IState, GettersTypes, MutationsTypes, ActionsTypes |
|
|
|
async [Action.AuthLogin]({commit, dispatch}, {email, password, remember = false}) { |
|
|
|
try { |
|
|
|
let [status, response] = await dispatch(Action.Post, { |
|
|
|
path: `/auth/login?use_cookies=${navigator.cookieEnabled}`, |
|
|
|
path: "/auth/login", |
|
|
|
useAuth: false, |
|
|
|
body: {email, password}}); |
|
|
|
if (status !== 200) { |
|
|
@ -213,18 +216,25 @@ export const actions: Actions<IState, GettersTypes, MutationsTypes, ActionsTypes |
|
|
|
/** |
|
|
|
* Load the user from local storage |
|
|
|
*/ |
|
|
|
[Action.AuthLoad]({getters, commit, dispatch}) { |
|
|
|
async [Action.AuthLoad]({getters, commit, dispatch}) { |
|
|
|
let token = getters.storedToken; |
|
|
|
if (!token) { |
|
|
|
return false; |
|
|
|
return; |
|
|
|
} |
|
|
|
try { |
|
|
|
commit(Mutation.UserLoad, token); |
|
|
|
await dispatch(Action.AuthVerify, undefined); |
|
|
|
} catch(e) { |
|
|
|
dispatch(Action.AuthForget, undefined); |
|
|
|
return false; |
|
|
|
} |
|
|
|
return true; |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* Verify the current authentication session |
|
|
|
*/ |
|
|
|
async [Action.AuthVerify]({getters}) { |
|
|
|
let token = getters.storedToken; |
|
|
|
// TODO
|
|
|
|
}, |
|
|
|
|
|
|
|
// Movies --------------------------------------------------------------------------------------
|
|
|
|