security upgrade
This commit is contained in:
+3
-5
@@ -33,6 +33,7 @@ function formatBytes(bytes) {
|
||||
}
|
||||
|
||||
function clearExpiredSession() {
|
||||
localStorage.removeItem("rustpad:auth-state");
|
||||
localStorage.removeItem("rustpad:auth-token");
|
||||
sessionStorage.removeItem("rustpad:auth-token");
|
||||
localStorage.removeItem("rustpad:nickname");
|
||||
@@ -42,11 +43,9 @@ function clearExpiredSession() {
|
||||
}
|
||||
|
||||
async function clearSessionIfInvalid() {
|
||||
const token = localStorage.getItem("rustpad:auth-token") || sessionStorage.getItem("rustpad:auth-token");
|
||||
if (!token) return;
|
||||
if (!localStorage.getItem("rustpad:auth-state")) return;
|
||||
try {
|
||||
const response = await fetch("/api/auth/me", {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
signal: AbortSignal.timeout(5000),
|
||||
});
|
||||
if (response.status === 401) clearExpiredSession();
|
||||
@@ -70,8 +69,7 @@ function validateUploadSize(body) {
|
||||
|
||||
function requestHeaders(options, body) {
|
||||
const headers = new Headers(options.headers || {});
|
||||
const authToken = localStorage.getItem("rustpad:auth-token") || sessionStorage.getItem("rustpad:auth-token");
|
||||
if (authToken && !headers.has("authorization")) headers.set("authorization", `Bearer ${authToken}`);
|
||||
headers.delete("x-rustpad-user-token");
|
||||
if (!(body instanceof FormData) && !headers.has("content-type")) headers.set("content-type", "application/json");
|
||||
return headers;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user