mirror of
https://github.com/filebrowser/filebrowser.git
synced 2024-06-07 23:00:43 +00:00
fix: expired token error
This commit is contained in:
parent
fc209f64de
commit
c3bd1188aa
@ -4,9 +4,13 @@ import { baseURL } from "@/utils/constants";
|
|||||||
export async function fetch(url, password = "") {
|
export async function fetch(url, password = "") {
|
||||||
url = removePrefix(url);
|
url = removePrefix(url);
|
||||||
|
|
||||||
const res = await fetchURL(`/api/public/share${url}`, {
|
const res = await fetchURL(
|
||||||
|
`/api/public/share${url}`,
|
||||||
|
{
|
||||||
headers: { "X-SHARE-PASSWORD": encodeURIComponent(password) },
|
headers: { "X-SHARE-PASSWORD": encodeURIComponent(password) },
|
||||||
});
|
},
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
let data = await res.json();
|
let data = await res.json();
|
||||||
data.url = `/share${url}`;
|
data.url = `/share${url}`;
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import store from "@/store";
|
import store from "@/store";
|
||||||
import { renew } from "@/utils/auth";
|
import { renew, logout } from "@/utils/auth";
|
||||||
import { baseURL } from "@/utils/constants";
|
import { baseURL } from "@/utils/constants";
|
||||||
import { encodePath } from "@/utils/url";
|
import { encodePath } from "@/utils/url";
|
||||||
|
|
||||||
export async function fetchURL(url, opts) {
|
export async function fetchURL(url, opts, auth = true) {
|
||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
opts.headers = opts.headers || {};
|
opts.headers = opts.headers || {};
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ export async function fetchURL(url, opts) {
|
|||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (res.headers.get("X-Renew-Token") === "true") {
|
if (auth && res.headers.get("X-Renew-Token") === "true") {
|
||||||
await renew(store.state.jwt);
|
await renew(store.state.jwt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,6 +33,10 @@ export async function fetchURL(url, opts) {
|
|||||||
const error = new Error(await res.text());
|
const error = new Error(await res.text());
|
||||||
error.status = res.status;
|
error.status = res.status;
|
||||||
|
|
||||||
|
if (auth && res.status == 401) {
|
||||||
|
logout();
|
||||||
|
}
|
||||||
|
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ func withUser(fn handleFunc) handleFunc {
|
|||||||
token, err := request.ParseFromRequest(r, &extractor{}, keyFunc, request.WithClaims(&tk))
|
token, err := request.ParseFromRequest(r, &extractor{}, keyFunc, request.WithClaims(&tk))
|
||||||
|
|
||||||
if err != nil || !token.Valid {
|
if err != nil || !token.Valid {
|
||||||
return http.StatusForbidden, nil
|
return http.StatusUnauthorized, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
expired := !tk.VerifyExpiresAt(time.Now().Add(time.Hour).Unix(), true)
|
expired := !tk.VerifyExpiresAt(time.Now().Add(time.Hour).Unix(), true)
|
||||||
|
Loading…
Reference in New Issue
Block a user