From 8685c8e87f382bf42da57c883b14a3e42120b2e8 Mon Sep 17 00:00:00 2001 From: Rafi Date: Thu, 23 Feb 2023 18:36:04 +0800 Subject: [PATCH] feat: auth plugin --- plugins/auth.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/plugins/auth.js b/plugins/auth.js index 5df17c8..3209b4e 100644 --- a/plugins/auth.js +++ b/plugins/auth.js @@ -25,12 +25,16 @@ const ENDPOINTS = { export default defineNuxtPlugin(() => { - const token = useCookie(COOKIE_OPTIONS.prefix + '.' + COOKIE_OPTIONS.tokenName, { + const tokenKey = COOKIE_OPTIONS.prefix + '.' + COOKIE_OPTIONS.tokenName + const refreshTokenKey = COOKIE_OPTIONS.prefix + '.' + COOKIE_OPTIONS.refreshTokenName + const tokenOptions = { maxAge: 60 * 5, - }) - const refreshToken = useCookie(COOKIE_OPTIONS.prefix + '.' + COOKIE_OPTIONS.refreshTokenName, { + } + const refreshTokenOptions = { maxAge: 60 * 60 * 24, - }) + } + const token = useCookie(tokenKey, tokenOptions) + const refreshToken = useCookie(refreshTokenKey, refreshTokenOptions) class Auth { constructor() { @@ -95,6 +99,8 @@ export default defineNuxtPlugin(() => { } async retrieveToken () { + const token = useCookie(tokenKey, tokenOptions) + const refreshToken = useCookie(refreshTokenKey, refreshTokenOptions) if (!refreshToken.value) { return null }