Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ export default async (ctx, inject) => {
ctx.$cookies.set(key, value);
return Promise.resolve();
},
removeItem: (key) => {
ctx.$cookies.remove(key);
return Promise.resolve()
}
},
mode: 'json',
autoRefresh: false,
Expand All @@ -49,8 +53,12 @@ export default async (ctx, inject) => {
const tokenData = jwtDecode(storedToken);
const validFor = tokenData.exp * 1000 - Date.now();
if (validFor < 300000) {
const { data } = await directus.auth.refresh();
directus.auth.token = data.access_token;
try {
const { data } = await directus.auth.refresh();
directus.auth.token = data.access_token;
} catch (error) {
// Nothing to do here, this will push to options.loginRoute route
}
} else {
directus.auth.token = storedToken;
}
Expand Down