mirror of
https://github.com/hay-kot/mealie.git
synced 2025-08-22 14:33:33 -07:00
refresh token on page refresh
This commit is contained in:
parent
c83a83d656
commit
b811ec14cd
5 changed files with 26 additions and 7 deletions
|
@ -47,7 +47,7 @@ const apiReq = {
|
|||
return response;
|
||||
} else return;
|
||||
});
|
||||
// processResponse(response);
|
||||
processResponse(response);
|
||||
return response;
|
||||
},
|
||||
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
import { baseURL } from "./api-utils";
|
||||
import { apiReq } from "./api-utils";
|
||||
import axios from "axios";
|
||||
const authPrefix = baseURL + "auth";
|
||||
const userPrefix = baseURL + "users";
|
||||
|
||||
const authURLs = {
|
||||
token: `${authPrefix}/token`,
|
||||
refresh: `${authPrefix}/refresh`,
|
||||
};
|
||||
|
||||
|
||||
const usersURLs = {
|
||||
users: `${userPrefix}`,
|
||||
self: `${userPrefix}/self`,
|
||||
|
@ -24,6 +25,12 @@ export default {
|
|||
});
|
||||
return response;
|
||||
},
|
||||
async refresh() {
|
||||
let response = await axios.get(authURLs.refresh).catch(function(event) {
|
||||
console.log("Fetch failed", event);
|
||||
});
|
||||
return response.data ? response.data : false;
|
||||
},
|
||||
async allUsers() {
|
||||
let response = await apiReq.get(usersURLs.users);
|
||||
return response.data;
|
||||
|
|
|
@ -63,6 +63,20 @@ const actions = {
|
|||
}
|
||||
},
|
||||
|
||||
async refreshToken({ commit, getters }) {
|
||||
if (!getters.getIsLoggedIn) {
|
||||
commit("setIsLoggedIn", false); // This is to be here... for some reasons? ¯\_(ツ)_/¯
|
||||
console.log("Not Logged In");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
let authResponse = await api.users.refresh();
|
||||
commit("setToken", authResponse.access_token);
|
||||
} catch {
|
||||
console.log("Failed Token Refresh, Logging Out...");
|
||||
commit("setIsLoggedIn", false);
|
||||
}
|
||||
},
|
||||
|
||||
async initTheme({ dispatch, getters }) {
|
||||
//If theme is empty resetTheme
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { vueApp } from "../main";
|
||||
|
||||
|
||||
// TODO: Migrate to Mixins
|
||||
const notifyHelpers = {
|
||||
baseCSS: "notify-base",
|
||||
error: "notify-error-color",
|
||||
|
|
|
@ -60,10 +60,8 @@ def get_long_token(
|
|||
)
|
||||
|
||||
|
||||
@router.post("/refresh")
|
||||
async def refresh_token(
|
||||
current_user: UserInDB = Depends(manager),
|
||||
):
|
||||
@router.get("/refresh")
|
||||
async def refresh_token(current_user: UserInDB = Depends(manager)):
|
||||
""" Use a valid token to get another token"""
|
||||
access_token = manager.create_access_token(
|
||||
data=dict(sub=current_user.email), expires=timedelta(hours=1)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue