({
ctx,
input,
}: InferProcedureOpts<typeof baseProcedure>)
| 17 | export const startDemoProcedure = once(() => baseProcedure.mutation(startDemo)); |
| 18 | |
| 19 | export async function startDemo({ |
| 20 | ctx, |
| 21 | input, |
| 22 | }: InferProcedureOpts<typeof baseProcedure>) { |
| 23 | // Generate random password values |
| 24 | |
| 25 | const passwordValues = { |
| 26 | hash: sodium.randombytes_buf(64), |
| 27 | key: wrapSymmetricKey(sodium.randombytes_buf(32)), |
| 28 | salt: new Uint8Array(sodium.randombytes_buf(16)), |
| 29 | }; |
| 30 | |
| 31 | // Register the demo account |
| 32 | |
| 33 | const user = await registerUser({ |
| 34 | ...input, |
| 35 | |
| 36 | demo: true, |
| 37 | |
| 38 | ip: ctx.req.ip, |
| 39 | userAgent: ctx.req.headers['user-agent'] ?? '', |
| 40 | |
| 41 | email: `demo-${nanoid()}`, |
| 42 | |
| 43 | passwordValues, |
| 44 | }); |
| 45 | |
| 46 | // Get the user's device |
| 47 | |
| 48 | const device = await getUserDevice({ |
| 49 | ip: ctx.req.ip, |
| 50 | userAgent: ctx.req.headers['user-agent'] ?? '', |
| 51 | userId: user.id, |
| 52 | }); |
| 53 | |
| 54 | // Generate a new session |
| 55 | |
| 56 | const sessionId = nanoid(); |
| 57 | |
| 58 | const { sessionKey } = await generateSessionValues({ |
| 59 | sessionId, |
| 60 | userId: user.id, |
| 61 | deviceId: device.id, |
| 62 | rememberSession: false, |
| 63 | reply: ctx.res, |
| 64 | }); |
| 65 | |
| 66 | // Return session values |
| 67 | |
| 68 | return { |
| 69 | userId: user.id, |
| 70 | sessionId, |
| 71 | |
| 72 | sessionKey, |
| 73 | |
| 74 | personalGroupId: user.personal_group_id, |
| 75 | |
| 76 | publicKeyring: user.public_keyring, |
nothing calls this directly
no test coverage detected