feat(tags): add auto-awarded profile tags and validation utilities.

This commit is contained in:
shay
2026-04-19 09:37:32 -04:00
parent ca74e91e3e
commit 58e794fd57
3 changed files with 206 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
// Per-username edit token issued by the backend at enrollment. Presented
// as `Authorization: Bearer` on mutating endpoints (PATCH settings,
// POST refresh). Stored in localStorage so a reload keeps the user in
// control of their own profile.
//
// Without this token the backend rejects mutations with HTTP 401. Token is
// only surfaced on the FIRST enroll for a given username — re-hitting the
// enroll path for an existing user returns no token, so we never blow away
// a previously-saved token.
const STORAGE_PREFIX = 'grs:edit_token:'
const keyFor = (username: string) => STORAGE_PREFIX + username.toLowerCase()
export function getEditToken(username: string): string | null {
if (!username) return null
try {
return window.localStorage.getItem(keyFor(username))
} catch {
return null
}
}
export function saveEditToken(username: string, token: string | null | undefined): void {
if (!username || !token) return
try {
window.localStorage.setItem(keyFor(username), token)
} catch {
// localStorage can throw in private mode — fall through silently.
}
}
export function authHeaders(username: string): Record<string, string> {
const t = getEditToken(username)
return t ? { Authorization: `Bearer ${t}` } : {}
}