Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { apiConfig } from '../config'
- import { Base64 } from 'js-base64'
- export default {
- user: {
- authenticated: false,
- username: ''
- },
- login (context, creds, redirect) {
- let header = {
- headers: {
- Authorization: 'Basic ' + Base64.encode(creds.username + ':' + creds.password),
- 'System-Id': apiConfig.systemId,
- 'Client-Id': apiConfig.clientId
- }
- }
- context.$http.get(apiConfig.apiUrl, header)
- .then(response => {
- localStorage.setItem('sessionId', response.headers['uri-append'])
- this.user.authenticated = true
- this.user.username = creds.username
- context.$router.push({name: redirect})
- })
- .catch(e => {
- console.log(e)
- context.isError = true
- context.credentials.username = ''
- context.credentials.password = ''
- })
- this.authenticated = this.user.authenticated
- },
- logout (context) {
- localStorage.removeItem('sessionId')
- this.user.authenticated = false
- this.authenticated = this.user.authenticated
- this.user.username = ''
- context.$router.push({ name: 'home' })
- },
- checkAuth (context) {
- const sessionId = localStorage.getItem('sessionId')
- if (sessionId) {
- this.user.authenticated = true
- this.authenticated = this.user.authenticated
- return sessionId
- } else {
- this.user.authenticated = false
- this.authenticated = this.user.authenticated
- this.user.username = ''
- if (context.$router) {
- context.$router.push({name: 'home'})
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement