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

Function getUserDevice

apps/app-server/src/utils/devices.ts:5–31  ·  view source on GitHub ↗
(input: {
  ip: string;
  userAgent: string;
  userId: string;

  dtrx?: DataTransaction;
})

Source from the content-addressed store, hash-verified

3import { getDeviceHash } from 'src/utils/crypto';
4
5export async function getUserDevice(input: {
6 ip: string;
7 userAgent: string;
8 userId: string;
9
10 dtrx?: DataTransaction;
11}) {
12 const deviceHash = getDeviceHash({
13 ip: input.ip,
14 userAgent: input.userAgent,
15 userId: input.userId,
16 });
17
18 let device = await DeviceModel.query()
19 .where('user_id', input.userId)
20 .where('hash', deviceHash)
21 .first();
22
23 if (device == null) {
24 device = await DeviceModel.query(input.dtrx?.trx).insert({
25 user_id: input.userId,
26 hash: deviceHash,
27 });
28 }
29
30 return device;
31}

Callers 2

startDemoFunction · 0.90
loginFunction · 0.90

Calls 2

getDeviceHashFunction · 0.90
insertMethod · 0.80

Tested by

no test coverage detected