Created
October 25, 2018 16:00
-
-
Save ufobat/4a042ee2d5dd8e8952c596c5025c9bbd to your computer and use it in GitHub Desktop.
This file contains 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
import Vue from 'vue'; | |
import Vuex from 'vuex'; | |
import { Module, VuexModule, Mutation, Action } from 'vuex-module-decorators'; | |
Vue.use(Vuex); | |
const debug = process.env.NODE_ENV !== 'production'; | |
interface LoginCredentials { | |
username: string; | |
password: string; | |
} | |
@Module | |
class Authentication extends VuexModule { | |
private authorizationHeader = ''; | |
@Mutation | |
public setAuthorizationHeader(newHeader: string) { | |
window.alert('setting: ' + newHeader); | |
this.authorizationHeader = newHeader; | |
window.alert('is now on: ' + this.authorizationHeader); | |
} | |
@Action | |
public async setLoginCredentials(payload: LoginCredentials) { | |
window.alert('user: ' + payload.username); | |
window.alert('pass: ' + payload.password); | |
const authHeader = window.btoa(payload.username + ':' + payload.password); | |
this.context.commit('setAuthorizationHeader', 'Basic ' + authHeader); | |
} | |
get authHeader(): string { | |
window.alert('called authHeader() -> ' + this.authorizationHeader); | |
return this.authorizationHeader; | |
} | |
} | |
export default new Vuex.Store({ | |
strict: debug, | |
modules: { | |
Authentication, | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment