Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/util/db-schema/auth.ts
1447 views
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { Table } from "./types";
7
import { SCHEMA as schema } from "./index";
8
9
Table({
10
name: "remember_me",
11
fields: {
12
hash: {
13
type: "string",
14
pg_type: "CHAR(127)",
15
},
16
value: {
17
type: "map",
18
},
19
account_id: {
20
type: "uuid",
21
},
22
expire: {
23
type: "timestamp",
24
},
25
},
26
rules: {
27
primary_key: "hash",
28
durability: "soft", // dropping this would just require a user to login again
29
pg_indexes: ["account_id"],
30
},
31
});
32
33
Table({
34
name: "auth_tokens",
35
fields: {
36
auth_token: {
37
type: "string",
38
pg_type: "CHAR(24)",
39
},
40
account_id: {
41
desc: "User who this auth token grants access to become",
42
type: "uuid",
43
render: { type: "account" },
44
},
45
expire: {
46
type: "timestamp",
47
render: { type: "timestamp", editable: false },
48
},
49
created: {
50
desc: "When this auth token was created",
51
type: "timestamp",
52
render: { type: "timestamp" },
53
},
54
created_by: {
55
desc: "User who created the auth token.",
56
type: "uuid",
57
render: { type: "account" },
58
},
59
is_admin: {
60
desc: "True if wser who created the auth token did so as an admin.",
61
type: "boolean",
62
},
63
},
64
rules: {
65
primary_key: "auth_token",
66
},
67
});
68
69
Table({
70
name: "crm_auth_tokens",
71
rules: {
72
virtual: "auth_tokens",
73
primary_key: "auth_token",
74
user_query: {
75
get: {
76
admin: true, // only admins can do get queries on this table
77
fields: {
78
account_id: null,
79
expire: null,
80
created: null,
81
created_by: null,
82
is_admin: null,
83
},
84
},
85
},
86
},
87
fields: schema.auth_tokens.fields,
88
});
89
90