optimize post migration
This commit is contained in:
@@ -59,7 +59,7 @@ export async function createChild(opts: {
|
||||
}
|
||||
|
||||
// Admin grants access to a child: creates the users auth record (or re-issues
|
||||
// OTP if they already exist) + upserts their user_configs. Returns the OTP and
|
||||
// OTP if they already exist) + upserts their otp. Returns the OTP and
|
||||
// shareable join link (using the whitespace-free handle) for QR display.
|
||||
export async function issueAccess(opts: {
|
||||
famId: string;
|
||||
@@ -67,23 +67,23 @@ export async function issueAccess(opts: {
|
||||
name: string;
|
||||
colour?: string;
|
||||
}) {
|
||||
const { famId, famSlug, name, colour } = opts;
|
||||
const { famId, famSlug, name } = opts;
|
||||
const username = handle(name);
|
||||
const otp = generateOtp();
|
||||
const updatedAt = new Date().toISOString();
|
||||
|
||||
const user = await createChild({ famId, famSlug, name, colour });
|
||||
const user = await createChild({ famId, famSlug, name, colour: opts.colour });
|
||||
|
||||
const pb = await createSuperClient();
|
||||
let config = await pb
|
||||
.collection('user_configs')
|
||||
.collection('otp')
|
||||
.getFirstListItem(`famId='${famId}' && userId='${user.id}'`)
|
||||
.catch(() => null);
|
||||
|
||||
if (config) {
|
||||
await pb.collection('user_configs').update(config.id, { otp, colour, updatedAt });
|
||||
await pb.collection('otp').update(config.id, { otp, updatedAt });
|
||||
} else {
|
||||
await pb.collection('user_configs').create({ famId, userId: user.id, otp, colour, updatedAt });
|
||||
await pb.collection('otp').create({ famId, userId: user.id, otp, updatedAt });
|
||||
}
|
||||
|
||||
return { otp, joinUrl: `/${famSlug}/join/${encodeURIComponent(username)}` };
|
||||
@@ -109,7 +109,7 @@ export async function redeemOtp(opts: { famSlug: string; username: string; otp:
|
||||
if (!user || user.role !== 'child') throw new Error('Invalid join link');
|
||||
|
||||
let config = await pb
|
||||
.collection('user_configs')
|
||||
.collection('otp')
|
||||
.getFirstListItem(`famId='${fam.id}' && userId='${user.id}'`)
|
||||
.catch(() => null);
|
||||
if (!config || config.otp !== otp) throw new Error('Invalid code');
|
||||
|
||||
Reference in New Issue
Block a user