mirror of
https://github.com/whoswhip/Sharpbin.git
synced 2026-12-06 02:48:43 +00:00
feat: reports; improved+simplifed modals; extractError funcction;
refactor: change jwt claims to lowercase; use response dtos for sensitive data fix: nullify user on token clears; change appsettings.dev View_Internal_API_Key
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { browser } from '$app/environment';
|
||||
import type { Cookies } from '@sveltejs/kit';
|
||||
import { user } from '$lib/stores/user';
|
||||
|
||||
const TOKEN_KEY = 'token';
|
||||
const REFRESH_TOKEN_KEY = 'refreshToken';
|
||||
@@ -36,6 +37,7 @@ export function clearTokens() {
|
||||
console.log('Clearing tokens');
|
||||
document.cookie = `${TOKEN_KEY}=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT`;
|
||||
document.cookie = `${REFRESH_TOKEN_KEY}=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT`;
|
||||
user.set(null);
|
||||
}
|
||||
|
||||
export async function refreshTokenIfNeeded() {
|
||||
|
||||
@@ -24,6 +24,25 @@ export function extractDateFromUUIDv7(uuid?: string): Date | null {
|
||||
return new Date(parseInt(timestampHex, 16));
|
||||
}
|
||||
|
||||
export function extractError(resData: unknown): string | null {
|
||||
if (!resData || typeof resData !== 'object') return null;
|
||||
|
||||
const data = resData as { errors?: unknown; message?: unknown };
|
||||
|
||||
if (data.errors && typeof data.errors === 'object') {
|
||||
return Object.values(data.errors as Record<string, unknown>)
|
||||
.flat()
|
||||
.filter((v) => typeof v === 'string')
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
if (typeof data.message === 'string') {
|
||||
return data.message;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
export function dateToRelativeString(
|
||||
date: Date,
|
||||
useSuffix = true,
|
||||
|
||||
@@ -2,7 +2,7 @@ export function parseTotpEnabled(tokenValue: string | null) {
|
||||
if (!tokenValue) return false;
|
||||
try {
|
||||
const payload = JSON.parse(atob(tokenValue.split('.')[1]));
|
||||
const flag = payload?.TOTP_Enabled ?? payload?.totp_enabled ?? payload?.totpEnabled;
|
||||
const flag = payload?.totp;
|
||||
if (typeof flag === 'string') return flag.toLowerCase() === 'true';
|
||||
return Boolean(flag);
|
||||
} catch {
|
||||
|
||||
Reference in New Issue
Block a user