Skip to content
This repository has been archived by the owner on Dec 16, 2020. It is now read-only.

Commit

Permalink
wip: Auth
Browse files Browse the repository at this point in the history
  • Loading branch information
Atinux committed Feb 5, 2019
1 parent 85e32a2 commit cb9d53d
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions services/auth.js
Expand Up @@ -16,20 +16,14 @@ export default class AuthService extends NuxtService {
}

async getUser (req, res) {
const cookies = Cookies(req, res)

// Get jwt cookie
const jwt = cookies.get('jwt')
if (!jwt) return

// Check if JWT is good
try {
this.$axios.setToken(jwt, 'Bearer')

// TODO
const user = await this.$services.me.show()
// Set expiration in 3 months
const expires = new Date()
expires.setMonth(expires.getMonth() + 3)
// TODO: Find a way to set cookie from WS
// Update jwt cookie
cookies.set('jwt', user.token, {
expires,
Expand All @@ -40,7 +34,8 @@ export default class AuthService extends NuxtService {
return user
} catch (err) {
if (err.response && err.response.status === 401) {
cookies.set('jwt') // Remove jwt cookie
// cookies.set('jwt') // Remove jwt cookie
// Find a way to remove cookie from WS?
this.$axios.setToken(false)
}
}
Expand Down

0 comments on commit cb9d53d

Please sign in to comment.