MCPcopy Create free account
hub / github.com/DeepNotesApp/DeepNotes / startDemo

Function startDemo

apps/app-server/src/trpc/api/sessions/start-demo.ts:19–94  ·  view source on GitHub ↗
({
  ctx,
  input,
}: InferProcedureOpts<typeof baseProcedure>)

Source from the content-addressed store, hash-verified

17export const startDemoProcedure = once(() => baseProcedure.mutation(startDemo));
18
19export 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,

Callers

nothing calls this directly

Calls 7

wrapSymmetricKeyFunction · 0.90
registerUserFunction · 0.90
getUserDeviceFunction · 0.90
generateSessionValuesFunction · 0.90
createPrivateKeyringFunction · 0.90
createSymmetricKeyringFunction · 0.90
unwrapSymmetricMethod · 0.65

Tested by

no test coverage detected