@budibase/worker 3.12.12 → 3.12.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/worker",
|
|
3
3
|
"email": "hi@budibase.com",
|
|
4
|
-
"version": "3.12.
|
|
4
|
+
"version": "3.12.14",
|
|
5
5
|
"description": "Budibase background service",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
7
|
"repository": {
|
|
@@ -113,5 +113,5 @@
|
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
},
|
|
116
|
-
"gitHead": "
|
|
116
|
+
"gitHead": "dbe8dd62a6714a1bf0768542434fdeca2f81052b"
|
|
117
117
|
}
|
|
@@ -53,12 +53,20 @@ async function passportCallback(
|
|
|
53
53
|
return ctx.throw(403, info ? info : "Unauthorized")
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
const
|
|
56
|
+
const loginResult = await authSdk.loginUser(user)
|
|
57
57
|
|
|
58
58
|
// set a cookie for browser access
|
|
59
|
-
setCookie(ctx, token, Cookie.Auth, { sign: false })
|
|
59
|
+
setCookie(ctx, loginResult.token, Cookie.Auth, { sign: false })
|
|
60
60
|
// set the token in a header as well for APIs
|
|
61
|
-
ctx.set(Header.TOKEN, token)
|
|
61
|
+
ctx.set(Header.TOKEN, loginResult.token)
|
|
62
|
+
|
|
63
|
+
// add session invalidation info to response headers for frontend to handle
|
|
64
|
+
if (loginResult.invalidatedSessionCount > 0) {
|
|
65
|
+
ctx.set(
|
|
66
|
+
"X-Session-Invalidated-Count",
|
|
67
|
+
loginResult.invalidatedSessionCount.toString()
|
|
68
|
+
)
|
|
69
|
+
}
|
|
62
70
|
}
|
|
63
71
|
|
|
64
72
|
export const login = async (
|
package/src/environment.ts
CHANGED
|
@@ -38,6 +38,8 @@ const environment = {
|
|
|
38
38
|
COUCH_DB_URL: process.env.COUCH_DB_URL,
|
|
39
39
|
REDIS_URL: process.env.REDIS_URL,
|
|
40
40
|
ACCOUNT_PORTAL_URL: process.env.ACCOUNT_PORTAL_URL,
|
|
41
|
+
INTERNAL_ACCOUNT_PORTAL_URL:
|
|
42
|
+
process.env.INTERNAL_ACCOUNT_PORTAL_URL || process.env.ACCOUNT_PORTAL_URL,
|
|
41
43
|
PLATFORM_URL: process.env.PLATFORM_URL,
|
|
42
44
|
APPS_URL: process.env.APPS_URL,
|
|
43
45
|
// ports
|
package/src/sdk/auth/auth.ts
CHANGED
|
@@ -18,12 +18,13 @@ import * as emails from "../../utilities/email"
|
|
|
18
18
|
export async function loginUser(user: User) {
|
|
19
19
|
const sessionId = coreUtils.newid()
|
|
20
20
|
const tenantId = tenancy.getTenantId()
|
|
21
|
-
await sessions.createASession(user._id!, {
|
|
21
|
+
const sessionResult = await sessions.createASession(user._id!, {
|
|
22
22
|
sessionId,
|
|
23
23
|
tenantId,
|
|
24
24
|
email: user.email,
|
|
25
25
|
})
|
|
26
|
-
|
|
26
|
+
|
|
27
|
+
const token = jwt.sign(
|
|
27
28
|
{
|
|
28
29
|
userId: user._id,
|
|
29
30
|
sessionId,
|
|
@@ -32,6 +33,11 @@ export async function loginUser(user: User) {
|
|
|
32
33
|
},
|
|
33
34
|
coreEnv.JWT_SECRET!
|
|
34
35
|
)
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
token,
|
|
39
|
+
invalidatedSessionCount: sessionResult.invalidatedSessionCount,
|
|
40
|
+
}
|
|
35
41
|
}
|
|
36
42
|
|
|
37
43
|
export async function logout(opts: PlatformLogoutOpts) {
|
|
@@ -68,5 +68,25 @@ describe("auth", () => {
|
|
|
68
68
|
expect(await sessions.getSessionsForUser(user._id!)).toHaveLength(0)
|
|
69
69
|
})
|
|
70
70
|
})
|
|
71
|
+
|
|
72
|
+
it("loginUser should return session invalidation count", async () => {
|
|
73
|
+
await context.doInTenant(structures.tenant.id(), async () => {
|
|
74
|
+
const user = await config.createUser()
|
|
75
|
+
|
|
76
|
+
const loginResult1 = await loginUser(user)
|
|
77
|
+
expect(loginResult1.invalidatedSessionCount).toBe(0)
|
|
78
|
+
|
|
79
|
+
const loginResult2 = await loginUser(user)
|
|
80
|
+
expect(loginResult2.invalidatedSessionCount).toBe(0)
|
|
81
|
+
|
|
82
|
+
const loginResult3 = await loginUser(user)
|
|
83
|
+
expect(loginResult3.invalidatedSessionCount).toBe(0)
|
|
84
|
+
|
|
85
|
+
const loginResult4 = await loginUser(user)
|
|
86
|
+
expect(loginResult4.invalidatedSessionCount).toBe(1)
|
|
87
|
+
|
|
88
|
+
expect(await sessions.getSessionsForUser(user._id!)).toHaveLength(3)
|
|
89
|
+
})
|
|
90
|
+
})
|
|
71
91
|
})
|
|
72
92
|
})
|