Compare commits

..

1 Commits

Author SHA1 Message Date
ff5371d867 Removed hard dependency on discord ID for auth system 2025-12-19 22:46:53 -05:00
2 changed files with 28 additions and 32 deletions

View File

@@ -46,32 +46,35 @@ passport.use(new OpenIDConnectStrategy({
//lookup existing user
const existing = await con.query(`SELECT id FROM members WHERE authentik_issuer = ? AND authentik_sub = ? LIMIT 1;`, [issuer, sub]);
let memberId: number;
let memberId: number | null = null;
//if member exists
if (existing.length > 0) {
memberId = existing[0].id;
} else {
//otherwise: create account
//otherwise: create account mode
const jwt = parseJwt(jwtClaims);
const discordID = jwt.discord.id as number;
const discordID = jwt.discord?.id as number;
//check if account is available to claim
memberId = await mapDiscordtoID(discordID);
if (discordID)
memberId = await mapDiscordtoID(discordID);
if (memberId === null) {
// create new account
if (discordID && memberId) {
// claim account
console.log("Claiming account");
const result = await con.query(
`UPDATE members SET authentik_sub = ?, authentik_issuer = ? WHERE id = ?;`,
[sub, issuer, memberId]
)
} else {
console.log("New Account");
// new account
const username = sub.username;
const result = await con.query(
`INSERT INTO members (name, authentik_sub, authentik_issuer) VALUES (?, ?, ?)`,
[username, sub, issuer]
)
memberId = Number(result.insertId);
} else {
// claim existing account
const result = await con.query(
`UPDATE members SET authentik_sub = ?, authentik_issuer = ? WHERE id = ?;`,
[sub, issuer, memberId]
)
}
}

View File

@@ -84,7 +84,7 @@ function loaStatus(loa: LOARequest): "Upcoming" | "Active" | "Overdue" | "Closed
if (now < start) return "Upcoming";
if (now >= start && now <= end) return "Active";
if (now > loa.extended_till || end) return "Overdue";
if (now > end) return "Overdue";
return "Overdue"; // fallback
}
@@ -197,7 +197,7 @@ function setPage(pagenum: number) {
<TableCell @click.stop="" class="text-right">
<DropdownMenu>
<DropdownMenuTrigger class="cursor-pointer">
<Button variant="ghost" size="icon">
<Button variant="ghost">
<Ellipsis class="size-6"></Ellipsis>
</Button>
</DropdownMenuTrigger>
@@ -220,11 +220,10 @@ function setPage(pagenum: number) {
</DropdownMenu>
</TableCell>
<TableCell>
<Button v-if="expanded === post.id" @click.stop="expanded = null" size="icon"
variant="ghost">
<Button v-if="expanded === post.id" @click.stop="expanded = null" variant="ghost">
<ChevronUp class="size-6" />
</Button>
<Button v-else @click.stop="expanded = post.id" size="icon" variant="ghost">
<Button v-else @click.stop="expanded = post.id" variant="ghost">
<ChevronDown class="size-6" />
</Button>
</TableCell>
@@ -234,24 +233,18 @@ function setPage(pagenum: number) {
<TableCell :colspan="8" class="p-0">
<div class="w-full p-3 mb-6 space-y-3">
<div class="flex justify-between items-start gap-4">
<div class="space-y-3 w-full">
<!-- Header -->
<div class="flex items-center gap-2">
<h4 class="text-sm font-semibold text-foreground">
Reason
</h4>
<Separator class="flex-1" />
</div>
<div class="flex-1">
<!-- Title -->
<p class="text-md font-semibold text-foreground">
Reason
</p>
<!-- Content -->
<div
class="rounded-lg border bg-muted/40 px-4 py-3 text-sm leading-relaxed whitespace-pre-wrap text-muted-foreground w-full">
{{ post.reason || 'No reason provided.' }}
</div>
<p
class="mt-1 text-md whitespace-pre-wrap leading-relaxed text-muted-foreground">
{{ post.reason }}
</p>
</div>
</div>
</div>
</TableCell>