Review a generated session helper

from Enums
TypeScript 6 advanced 10 min 4 issues to find

Review this generated session and role helper.

Parse untrusted session JSON, accept only known roles and future finite expiry times, list serialized role values for a select control, and authorize deletion only for administrators.

TypeScript
enum AccessRole {
  Reader = "READER",
  Editor = "EDITOR",
  Admin = "ADMIN",
}

interface SessionPayload {
  role: AccessRole;
  expiresAt: number;
}

function parseSession(raw: string): SessionPayload {
  const session = JSON.parse(raw) as SessionPayload;
  return session;
}

function roleOptions(): string[] {
  return Object.keys(AccessRole);
}

function canDelete(role: AccessRole): boolean {
  return role !== AccessRole.Reader && role !== AccessRole.Editor;
}

generated code is illustrative, not from any one model

Open in playground
Report an error