Files
lunch/lib/auth/invitations.ts
kai 2c40721490
release / which version (push) Successful in 1s
release / olares chart · sanity (push) Successful in 5s
release / app (push) Successful in 1m9s
release / tag and release (push) Successful in 2s
Teen role with own passkey, pictures for older children (26.11.19) (#20)
2026-11-07 06:50:03 +00:00

38 lines
1.2 KiB
TypeScript

import "server-only";
import type { PoolClient } from "pg";
import { hashToken } from "./tokens";
export type OpenInvitation = {
id: string;
householdId: string;
householdName: string;
memberId: string | null;
displayName: string | null;
memberName: string | null;
role: "admin" | "member" | "teen";
};
/** Die gültige, unbenutzte Einladung zum Link — oder null. In withAuth. */
export async function findInvitation(client: PoolClient, token: string): Promise<OpenInvitation | null> {
const { rows } = await client.query(
`select i.id, i.household_id, h.name as household_name, i.member_id, i.display_name, i.role, m.display_name as member_name
from invitations i
join households h on h.id = i.household_id
left join members m on m.id = i.member_id
where i.token_hash = $1 and i.used_at is null and i.expires_at > now()`,
[hashToken(token)],
);
const r = rows[0];
return r
? {
id: r.id,
householdId: r.household_id,
householdName: r.household_name,
memberId: r.member_id,
displayName: r.display_name,
memberName: r.member_name,
role: r.role,
}
: null;
}