Guest User

Untitled

a guest
Oct 25th, 2018
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. import Vue from 'vue';
  2. import Vuex from 'vuex';
  3. import { Module, VuexModule, Mutation, Action } from 'vuex-module-decorators';
  4.  
  5. Vue.use(Vuex);
  6.  
  7. const debug = process.env.NODE_ENV !== 'production';
  8.  
  9. interface LoginCredentials {
  10. username: string;
  11. password: string;
  12. }
  13.  
  14. @Module
  15. class Authentication extends VuexModule {
  16. private authorizationHeader = '';
  17.  
  18. @Mutation
  19. public setAuthorizationHeader(newHeader: string) {
  20. window.alert('setting: ' + newHeader);
  21. this.authorizationHeader = newHeader;
  22. window.alert('is now on: ' + this.authorizationHeader);
  23. }
  24.  
  25. @Action
  26. public async setLoginCredentials(payload: LoginCredentials) {
  27. window.alert('user: ' + payload.username);
  28. window.alert('pass: ' + payload.password);
  29.  
  30. const authHeader = window.btoa(payload.username + ':' + payload.password);
  31. this.context.commit('setAuthorizationHeader', 'Basic ' + authHeader);
  32. }
  33.  
  34. get authHeader(): string {
  35. window.alert('called authHeader() -> ' + this.authorizationHeader);
  36. return this.authorizationHeader;
  37. }
  38. }
  39.  
  40. export default new Vuex.Store({
  41. strict: debug,
  42. modules: {
  43. Authentication,
  44. },
  45. });
Add Comment
Please, Sign In to add comment