v2: global player, infinite scroll, image picker, threaded comments

This commit is contained in:
khannurien
2026-03-21 13:55:22 +00:00
parent be426eb150
commit 7c098e7c4c
48 changed files with 4346 additions and 711 deletions

View File

@@ -4,6 +4,15 @@ import { AuthContext } from "../contexts/AuthContext.ts";
import { type AuthResponse } from "../model.ts";
function isTokenExpired(token: string): boolean {
try {
const payload = JSON.parse(atob(token.split(".")[1]));
return typeof payload.exp === "number" && payload.exp * 1000 < Date.now();
} catch {
return true;
}
}
export const useAuth = () => {
const { authResponse, setAuthResponse } = useContext(AuthContext);
@@ -19,6 +28,13 @@ export const useAuth = () => {
const authFetch = async (input: RequestInfo, init: RequestInit = {}) => {
const token = authResponse?.token;
if (token && isTokenExpired(token)) {
logout();
// Return a synthetic 401 so callers handle it consistently
return new Response(null, { status: 401 });
}
const isFormData = init.body instanceof FormData;
const res = await fetch(input, {