Question: I need to replace all of the authentication code that is in this file with better, Vue authentication. Not going to be storing the username

I need to replace all of the authentication code that is in this file with better, Vue authentication. Not going to be storing the username or pass but instead as a JSON. This is my code:

const API_URL = 'http://localhost:8000/' const LOGIN_URL = API_URL + 'auth/login'

export default { user: { authenticated: false },

login (context, creds, redirect) { axios({ method: 'POST', url: LOGIN_URL, withCredentials: false, headers: { 'Content-Type': 'application/json', 'Access-Control-Allow-Origin': '*' }, data: creds }).then( resp => { localStorage.setItem('access_token', resp.data.access_token)

this.user.authenticated = true if (redirect) { Router.go(redirect) } }, err => { context.error = err.message } ) },

logout () { localStorage.removeItem('access_token') this.user.authenticated = false },

checkAuth () { var jwt = localStorage.getItem('access_token') if (jwt) { this.user.authenticated = true } else { this.user.authenticated = false } } }

*****************************************************************************

I need to use this code to replace the Auth Part.

import Vue from 'vue' import VueAxios from 'vue-axios' import VueAuthenticate from 'vue-authenticate' import axios from 'axios'; Vue.use(VueAxios, axios) Vue.use(VueAuthenticate, { baseUrl: 'http://localhost:3000', // Your API domain providers: { github: { clientId: '', redirectUri: 'http://localhost:8080/auth/callback' // Your client app URL } } })
new Vue({ methods: { login: function () { this.$auth.login({ email, password }).then(function () { // Execute application logic after successful login }) }, register: function () { this.$auth.register({ name, email, password }).then(function () { // Execute application logic after successful registration }) } } })

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!