Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/conat/hub/api/util.ts
1452 views
1
export const authFirst = ({ args, account_id, project_id }) => {
2
if (args[0] == null) {
3
args[0] = {} as any;
4
}
5
if (account_id) {
6
args[0].account_id = account_id;
7
} else if (project_id) {
8
args[0].project_id = project_id;
9
}
10
return args;
11
};
12
13
export const noAuth = ({ args }) => args;
14
15
// make no changes, except throw error if account_id not set (i.e., user not signed in)
16
export const requireAccount = ({ args, account_id }) => {
17
if (!account_id) {
18
throw Error("user must be signed in");
19
}
20
return args;
21
};
22
23
export const authFirstRequireAccount = async ({ args, account_id }) => {
24
if (args[0] == null) {
25
args[0] = {} as any;
26
}
27
if (!account_id) {
28
throw Error("user must be signed in");
29
}
30
args[0].account_id = account_id;
31
return args;
32
};
33
34
35