Skip to content

Commit 2355109

Browse files
committed
Merge branch 'develop'
2 parents 85be05a + 0bc2755 commit 2355109

File tree

21 files changed

+327
-123
lines changed

21 files changed

+327
-123
lines changed

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@inspatial/cloud",
3-
"version": "0.7.14",
3+
"version": "0.7.15",
44
"license": "Apache-2.0",
55
"exports": {
66
".": "./mod.ts",

src/auth/actions/auth-check.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { CloudAPIAction } from "~/api/cloud-action.ts";
1+
import { defineAPIAction } from "../../api/cloud-action.ts";
22

3-
const authCheck = new CloudAPIAction("authCheck", {
3+
const authCheck = defineAPIAction("authCheck", {
44
description: "Check if user is authenticated",
55
action({ inRequest }) {
66
const user = inRequest.context.get("user");

src/auth/actions/get-account.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { CloudAPIAction } from "../../api/cloud-action.ts";
1+
import { defineAPIAction } from "../../api/cloud-action.ts";
22
import type { SessionData } from "../types.ts";
33

4-
export const getAccount = new CloudAPIAction("getAccount", {
4+
export const getAccount = defineAPIAction("getAccount", {
55
description: "Gets the account for the current authenticated user",
66
async action({ inRequest, inCloud }) {
77
const user = inRequest.context.get<SessionData>("user");

src/auth/actions/login.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { CloudAPIAction } from "~/api/cloud-action.ts";
1+
import { defineAPIAction } from "~/api/cloud-action.ts";
22

33
import { raiseServerException } from "~/serve/server-exception.ts";
44

5-
const login = new CloudAPIAction("login", {
5+
const login = defineAPIAction("login", {
66
label: "Login",
77
description: "Login to the system",
88
authRequired: false,

src/auth/actions/logout.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { CloudAPIAction } from "~/api/cloud-action.ts";
1+
import { defineAPIAction } from "@inspatial/cloud";
22

3-
const logout = new CloudAPIAction("logout", {
3+
const logout = defineAPIAction("logout", {
44
label: "Logout",
55
description: "Logout user",
66
async action({ inCloud, inRequest, inResponse }) {

src/auth/actions/register-account.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { CloudAPIAction } from "~/api/cloud-action.ts";
21
import { raiseCloudException } from "~/serve/exeption/cloud-exception.ts";
2+
import { defineAPIAction } from "@inspatial/cloud";
33

4-
export const registerAccount = new CloudAPIAction("registerAccount", {
4+
export const registerAccount = defineAPIAction("registerAccount", {
55
label: "Register Account",
66
description: "Create a new acount and assign the given user as the owner.",
77
authRequired: false,
@@ -33,11 +33,10 @@ export const registerAccount = new CloudAPIAction("registerAccount", {
3333
});
3434
await user.save();
3535
await user.runAction("setPassword", { password });
36-
const account = await orm.createEntry("account", {
36+
await orm.createEntry("account", {
3737
name: `${firstName} ${lastName}'s Account`,
3838
users: [{ user: user.$id, isOwner: true }],
3939
});
40-
await account.enqueueAction("initialize");
4140
return await inCloud.auth.createUserSession(user, inRequest, inResponse);
4241
},
4342
params: [{

src/auth/actions/register-user.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { CloudAPIAction } from "~/api/cloud-action.ts";
1+
import { defineAPIAction } from "~/api/cloud-action.ts";
22
import { raiseCloudException } from "../../serve/exeption/cloud-exception.ts";
33

4-
const registerUser = new CloudAPIAction("registerUser", {
4+
const registerUser = defineAPIAction("registerUser", {
55
description: "Register a new user",
66
hideFromApi: true,
77
async action({ orm, params }) {

src/auth/actions/reset-password.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { CloudAPIAction } from "~/api/cloud-action.ts";
1+
import { defineAPIAction } from "~/api/cloud-action.ts";
22

3-
export const resetPassword = new CloudAPIAction("resetPassword", {
3+
export const resetPassword = defineAPIAction("resetPassword", {
44
description: "Reset user password",
55
authRequired: false,
66
label: "Reset Password",

src/auth/actions/set-new-password.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { CloudAPIAction } from "~/api/cloud-action.ts";
1+
import { defineAPIAction } from "~/api/cloud-action.ts";
22
import { raiseServerException } from "~/serve/server-exception.ts";
33

4-
export const setNewPassword = new CloudAPIAction("setNewPassword", {
4+
export const setNewPassword = defineAPIAction("setNewPassword", {
55
description: "Reset user password",
66
authRequired: false,
77
async action({ orm, params }) {

src/auth/actions/switch-account.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { defineAPIAction } from "../../api/cloud-action.ts";
2+
import { raiseServerException } from "../../serve/server-exception.ts";
3+
import type { SessionData } from "../types.ts";
4+
5+
export const switchAccount = defineAPIAction("switchAccount", {
6+
label: "Switch Logged-in Account",
7+
description:
8+
"Switch the current logged-in account to another account that the user has access to",
9+
params: [{
10+
key: "accountId",
11+
label: "Account ID",
12+
type: "DataField",
13+
description: "The ID of the account to switch to",
14+
required: true,
15+
}],
16+
async action({
17+
inCloud,
18+
inRequest,
19+
params,
20+
}) {
21+
const { accountId } = params;
22+
const user = inRequest.context.get<SessionData>("user");
23+
if (!user) {
24+
raiseServerException(401, "unauthorized");
25+
}
26+
const foundId = user.accounts.find((acc) => acc.accountId === accountId);
27+
if (!foundId) {
28+
raiseServerException(403, "forbidden");
29+
}
30+
user.accountId = accountId;
31+
const orm = inCloud.orm.withUser(inCloud.orm.systemGobalUser);
32+
const sessionEntry = await orm.findEntry("userSession", {
33+
sessionId: user.sessionId,
34+
});
35+
if (!sessionEntry) {
36+
raiseServerException(401, "unauthorized");
37+
}
38+
sessionEntry.update({
39+
sessionData: user,
40+
});
41+
await sessionEntry.save();
42+
inRequest.context.update("user", user);
43+
inCloud.inCache.setValue("userSession", user.sessionId, user);
44+
return user;
45+
},
46+
});

0 commit comments

Comments
 (0)