Created
September 29, 2021 08:10
-
-
Save ispoljari/5f8be1db71430628993d61d4eb202c58 to your computer and use it in GitHub Desktop.
AuthModule
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Module({ | |
| stateFactory: true, | |
| namespaced: true, | |
| }) | |
| export default class AuthModule extends VuexModule { | |
| userData?: UserData | undefined = undefined; | |
| prevRouteList: Routes[] = []; | |
| error?: services.ICognitoError | undefined = undefined; | |
| isLoading = false; | |
| ... | |
| @VuexMutation | |
| setIsLoading(isLoading: boolean) { | |
| this.isLoading = isLoading; | |
| } | |
| ... | |
| @VuexAction({ rawError: true }) | |
| async register(registerData: { email: string; password: string }): Promise<any> { | |
| this.context.commit('setIsLoading', true); | |
| this.context.commit('setError', undefined); | |
| this.context.commit('setInitiateRegistration', false); | |
| this.context.dispatch('setEmail', registerData.email); | |
| try { | |
| const { user } = await services.register(registerData.email, registerData.password); | |
| if (user) { | |
| this.context.dispatch('pushPrevRoute', Routes.emailVerification); | |
| this.context.commit('setInitiateRegistration', true); | |
| } | |
| } catch (error: any) { | |
| this.context.commit('setError', error); | |
| this.context.commit('setInitiateRegistration', false); | |
| } | |
| this.context.commit('setIsLoading', false); | |
| } | |
| ... | |
| @MutationAction | |
| setEmail(email: string) { ... } | |
| ... | |
| get getEmail() { | |
| return this.email; | |
| } | |
| ... | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment