@stacksjs/defaults 0.74.58 → 0.74.60

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.
@@ -35,10 +35,13 @@ export default new Action({
35
35
  // cannot be followed by this old in-flight login minting fresh access.
36
36
  const decision = await Auth.withVerifiedCredentials({ email, password }, async (authedUser) => {
37
37
  const { enabled: twoFactorEnabled } = await getTwoFactorState(authedUser.id as number)
38
+ const policy = resolveBrowserSessionPolicy(remember)
38
39
  if (twoFactorEnabled) {
39
- return { kind: 'challenge' as const, token: await createTwoFactorChallenge(authedUser.id as number) }
40
+ return {
41
+ kind: 'challenge' as const,
42
+ token: await createTwoFactorChallenge(authedUser.id as number, { remembered: policy.remembered }),
43
+ }
40
44
  }
41
- const policy = resolveBrowserSessionPolicy(remember)
42
45
  return {
43
46
  kind: 'login' as const,
44
47
  result: await Auth.loginUsingId(authedUser.id as number, {
@@ -1,5 +1,5 @@
1
1
  import { Action } from '@stacksjs/actions'
2
- import { Auth, clearAuthCookie, requestToken } from '@stacksjs/auth'
2
+ import { Auth, browserSessionLogoutRedirect, clearAuthCookie, requestToken } from '@stacksjs/auth'
3
3
  import { getCurrentRequest, response } from '@stacksjs/router'
4
4
 
5
5
  export default new Action({
@@ -9,16 +9,17 @@ export default new Action({
9
9
  async handle() {
10
10
  const request = getCurrentRequest()
11
11
  const usesDatabaseSession = !requestToken(request) && !!request?.cookie?.('session_id')
12
+ const redirect = browserSessionLogoutRedirect(request)
12
13
  await Auth.logout()
13
14
 
14
15
  // Clearing is separate from revoking, and both are needed. Revoking alone
15
16
  // leaves the browser sending a dead cookie on every request; clearing alone
16
17
  // leaves a copied cookie valid for the token's whole lifetime, which would
17
18
  // make "log out on a shared computer" mean only "hide the key".
18
- const result = response.json(
19
- { message: 'Successfully logged out' },
20
- { headers: { 'Set-Cookie': clearAuthCookie() } },
21
- )
19
+ const result = redirect
20
+ ? response.redirect(redirect, 303)
21
+ : response.json({ message: 'Successfully logged out' })
22
+ result.headers.append('Set-Cookie', clearAuthCookie())
22
23
  if (usesDatabaseSession)
23
24
  result.headers.append('Set-Cookie', clearAuthCookie({ name: 'session_id' }))
24
25
  return result
@@ -1,5 +1,5 @@
1
1
  import { Action } from '@stacksjs/actions'
2
- import { Auth, authCookie, register } from '@stacksjs/auth'
2
+ import { Auth, authCookieForBrowserSession, register, resolveBrowserSessionPolicy } from '@stacksjs/auth'
3
3
  import { dispatch } from '@stacksjs/events'
4
4
  import { response } from '@stacksjs/router'
5
5
  import { schema } from '@stacksjs/validation'
@@ -29,9 +29,13 @@ export default new Action({
29
29
  const email = request.get('email')
30
30
  const password = request.get('password')
31
31
  const name = request.get('name')
32
+ const policy = resolveBrowserSessionPolicy(request.get('remember'))
32
33
 
33
34
  const referralCode = request.get('referralCode')
34
- const result = await register({ email, password, name, referralCode: typeof referralCode === 'string' ? referralCode : undefined })
35
+ const result = await register(
36
+ { email, password, name, referralCode: typeof referralCode === 'string' ? referralCode : undefined },
37
+ { expiresInMinutes: policy.expiresInMinutes, withRefreshToken: policy.withRefreshToken },
38
+ )
35
39
 
36
40
  if (result) {
37
41
  const user = await Auth.getUserFromToken(result.token)
@@ -72,7 +76,7 @@ export default new Action({
72
76
  email: user?.email,
73
77
  name: user?.name,
74
78
  },
75
- }, { headers: { 'Set-Cookie': authCookie(result.token) } })
79
+ }, { headers: { 'Set-Cookie': authCookieForBrowserSession(result.token, result.expiresIn) } })
76
80
  }
77
81
 
78
82
  return response.error('Registration failed')
@@ -1,5 +1,5 @@
1
1
  import { Action } from '@stacksjs/actions'
2
- import { Auth, authCookie, verifyTwoFactorLoginCode, withTwoFactorChallenge } from '@stacksjs/auth'
2
+ import { Auth, authCookieForBrowserSession, resolveBrowserSessionPolicy, verifyTwoFactorLoginCode, withTwoFactorChallenge } from '@stacksjs/auth'
3
3
  import { response } from '@stacksjs/router'
4
4
  import { schema } from '@stacksjs/validation'
5
5
 
@@ -27,9 +27,13 @@ export default new Action({
27
27
  // (whether the code was right or wrong) must start over from
28
28
  // LoginAction, not retry — mirrors the WebAuthn challenge
29
29
  // delete-on-read semantics in passkey.ts (stacksjs/stacks#1866).
30
- const result = await withTwoFactorChallenge(challengeToken, async (userId) => {
30
+ const result = await withTwoFactorChallenge(challengeToken, async (userId, challenge) => {
31
31
  if (!await verifyTwoFactorLoginCode(userId, code)) return null
32
- return Auth.loginUsingId(userId)
32
+ const policy = resolveBrowserSessionPolicy(challenge.remembered)
33
+ return Auth.loginUsingId(userId, {
34
+ expiresInMinutes: policy.expiresInMinutes,
35
+ withRefreshToken: policy.withRefreshToken,
36
+ })
33
37
  })
34
38
  if (!result)
35
39
  return response.unauthorized('Invalid or expired login attempt. Please sign in again.')
@@ -51,6 +55,6 @@ export default new Action({
51
55
  email: user?.email,
52
56
  name: user?.name,
53
57
  },
54
- }, { headers: { 'Set-Cookie': authCookie(result.token) } })
58
+ }, { headers: { 'Set-Cookie': authCookieForBrowserSession(result.token, result.expiresIn) } })
55
59
  },
56
60
  })
@@ -2,7 +2,7 @@
2
2
  "publisher": "Stacks",
3
3
  "name": "vscode-stacks",
4
4
  "displayName": "Stacks",
5
- "version": "0.74.58",
5
+ "version": "0.74.60",
6
6
  "description": "A modern Stacks development environment.",
7
7
  "license": "MIT",
8
8
  "funding": "https://github.com/sponsors/chrisbbreuer",
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/defaults",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.74.58",
5
+ "version": "0.74.60",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "git+https://github.com/stacksjs/stacks.git",
@@ -55,7 +55,7 @@
55
55
  "dependencies": {
56
56
  "@iconify-json/f7": "^1.2.2",
57
57
  "@iconify-json/hugeicons": "^1.2.27",
58
- "@stacksjs/mobile": "^0.74.58",
58
+ "@stacksjs/mobile": "^0.74.60",
59
59
  "@stacksjs/sanitizer": "^0.2.113",
60
60
  "ts-qr-codes": "^0.1.8"
61
61
  }