Skip to content

Instantly share code, notes, and snippets.

@ufobat
Created October 25, 2018 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ufobat/4a042ee2d5dd8e8952c596c5025c9bbd to your computer and use it in GitHub Desktop.
Save ufobat/4a042ee2d5dd8e8952c596c5025c9bbd to your computer and use it in GitHub Desktop.
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