@aura-stack/auth 0.1.0-rc.9 → 0.1.0

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.
Files changed (116) hide show
  1. package/dist/@types/index.cjs +15 -15
  2. package/dist/@types/index.d.ts +7 -31
  3. package/dist/@types/index.js +1 -1
  4. package/dist/@types/router.d.cjs +1 -1
  5. package/dist/@types/router.d.d.ts +7 -7
  6. package/dist/@types/utility.cjs +15 -15
  7. package/dist/@types/utility.d.ts +6 -6
  8. package/dist/@types/utility.js +1 -1
  9. package/dist/actions/callback/access-token.cjs +143 -143
  10. package/dist/actions/callback/access-token.d.ts +15 -20
  11. package/dist/actions/callback/access-token.js +8 -4
  12. package/dist/actions/callback/callback.cjs +437 -455
  13. package/dist/actions/callback/callback.d.ts +10 -12
  14. package/dist/actions/callback/callback.js +16 -12
  15. package/dist/actions/callback/userinfo.cjs +131 -134
  16. package/dist/actions/callback/userinfo.d.ts +9 -9
  17. package/dist/actions/callback/userinfo.js +10 -6
  18. package/dist/actions/csrfToken/csrfToken.cjs +162 -171
  19. package/dist/actions/csrfToken/csrfToken.d.ts +3 -3
  20. package/dist/actions/csrfToken/csrfToken.js +12 -8
  21. package/dist/actions/index.cjs +746 -773
  22. package/dist/actions/index.d.ts +13 -13
  23. package/dist/actions/index.js +34 -18
  24. package/dist/actions/session/session.cjs +149 -155
  25. package/dist/actions/session/session.d.ts +3 -3
  26. package/dist/actions/session/session.js +11 -7
  27. package/dist/actions/signIn/authorization.cjs +231 -249
  28. package/dist/actions/signIn/authorization.d.ts +12 -18
  29. package/dist/actions/signIn/authorization.js +16 -6
  30. package/dist/actions/signIn/signIn.cjs +396 -423
  31. package/dist/actions/signIn/signIn.d.ts +10 -10
  32. package/dist/actions/signIn/signIn.js +14 -10
  33. package/dist/actions/signOut/signOut.cjs +417 -440
  34. package/dist/actions/signOut/signOut.d.ts +3 -3
  35. package/dist/actions/signOut/signOut.js +15 -11
  36. package/dist/assert.cjs +35 -36
  37. package/dist/assert.d.ts +4 -4
  38. package/dist/assert.js +10 -2
  39. package/dist/chunk-256KIVJL.js +85 -96
  40. package/dist/chunk-42XB3YCW.js +19 -17
  41. package/dist/chunk-6SM22VVJ.js +13 -10
  42. package/dist/chunk-CAKJT3KS.js +84 -69
  43. package/dist/chunk-E3OXBRYF.js +19 -17
  44. package/dist/chunk-EBPE35JT.js +28 -26
  45. package/dist/chunk-FIPU4MLT.js +18 -16
  46. package/dist/chunk-FJUDBLCP.js +50 -43
  47. package/dist/chunk-FKRDCWBF.js +19 -17
  48. package/dist/chunk-GZU3RBTB.js +51 -40
  49. package/dist/chunk-HGJ4TXY4.js +132 -100
  50. package/dist/chunk-HMRKN75I.js +63 -63
  51. package/dist/chunk-IKHPGFCW.js +11 -9
  52. package/dist/chunk-JAPMIE6S.js +7 -5
  53. package/dist/chunk-KRNOMBXQ.js +19 -17
  54. package/dist/chunk-LLR722CL.js +91 -70
  55. package/dist/chunk-RLT4RFKV.js +39 -30
  56. package/dist/chunk-SJPDVKUS.js +107 -88
  57. package/dist/chunk-SMQO5WD7.js +26 -16
  58. package/dist/chunk-STHEPPUZ.js +8 -6
  59. package/dist/chunk-UJJ7R56J.js +47 -37
  60. package/dist/chunk-UTDLUEEG.js +27 -21
  61. package/dist/chunk-VFTYH33W.js +54 -37
  62. package/dist/chunk-XXJKNKGQ.js +33 -23
  63. package/dist/chunk-ZV4BH47P.js +132 -134
  64. package/dist/cookie.cjs +169 -175
  65. package/dist/cookie.d.ts +23 -51
  66. package/dist/cookie.js +34 -34
  67. package/dist/error.cjs +75 -75
  68. package/dist/error.d.ts +30 -30
  69. package/dist/error.js +15 -8
  70. package/dist/headers.cjs +28 -28
  71. package/dist/headers.d.ts +2 -2
  72. package/dist/headers.js +6 -2
  73. package/dist/index-DpfbvTZ_.d.ts +249 -298
  74. package/dist/index.cjs +936 -969
  75. package/dist/index.d.ts +10 -31
  76. package/dist/index.js +70 -50
  77. package/dist/jose.cjs +61 -64
  78. package/dist/jose.d.ts +8 -8
  79. package/dist/jose.js +9 -5
  80. package/dist/oauth/bitbucket.cjs +38 -38
  81. package/dist/oauth/bitbucket.d.ts +7 -7
  82. package/dist/oauth/bitbucket.js +6 -2
  83. package/dist/oauth/discord.cjs +48 -48
  84. package/dist/oauth/discord.d.ts +7 -7
  85. package/dist/oauth/discord.js +6 -2
  86. package/dist/oauth/figma.cjs +39 -39
  87. package/dist/oauth/figma.d.ts +7 -7
  88. package/dist/oauth/figma.js +6 -2
  89. package/dist/oauth/github.cjs +31 -31
  90. package/dist/oauth/github.d.ts +7 -7
  91. package/dist/oauth/github.js +6 -2
  92. package/dist/oauth/gitlab.cjs +39 -39
  93. package/dist/oauth/gitlab.d.ts +7 -7
  94. package/dist/oauth/gitlab.js +6 -2
  95. package/dist/oauth/index.cjs +180 -180
  96. package/dist/oauth/index.d.ts +7 -26
  97. package/dist/oauth/index.js +36 -9
  98. package/dist/oauth/spotify.cjs +39 -39
  99. package/dist/oauth/spotify.d.ts +7 -7
  100. package/dist/oauth/spotify.js +6 -2
  101. package/dist/oauth/x.cjs +39 -39
  102. package/dist/oauth/x.d.ts +7 -7
  103. package/dist/oauth/x.js +6 -2
  104. package/dist/response.cjs +27 -27
  105. package/dist/response.d.ts +2 -2
  106. package/dist/response.js +6 -2
  107. package/dist/schemas.cjs +91 -91
  108. package/dist/schemas.d.ts +93 -126
  109. package/dist/schemas.js +18 -18
  110. package/dist/secure.cjs +95 -98
  111. package/dist/secure.d.ts +17 -17
  112. package/dist/secure.js +18 -4
  113. package/dist/utils.cjs +119 -132
  114. package/dist/utils.d.ts +11 -26
  115. package/dist/utils.js +21 -21
  116. package/package.json +2 -2
@@ -1,93 +1,112 @@
1
- import { createRedirectTo } from "./chunk-CAKJT3KS.js"
2
- import { expireCookie, getCookie, secureCookieOptions } from "./chunk-ZV4BH47P.js"
3
- import { cacheControl } from "./chunk-STHEPPUZ.js"
4
- import { verifyCSRF } from "./chunk-GZU3RBTB.js"
5
- import { getNormalizedOriginPath } from "./chunk-256KIVJL.js"
6
- import { InvalidCsrfTokenError, InvalidRedirectToError } from "./chunk-FJUDBLCP.js"
7
- import { AuraResponse } from "./chunk-JAPMIE6S.js"
1
+ import {
2
+ createRedirectTo
3
+ } from "./chunk-CAKJT3KS.js";
4
+ import {
5
+ expireCookie,
6
+ getCookie,
7
+ secureCookieOptions
8
+ } from "./chunk-ZV4BH47P.js";
9
+ import {
10
+ cacheControl
11
+ } from "./chunk-STHEPPUZ.js";
12
+ import {
13
+ verifyCSRF
14
+ } from "./chunk-GZU3RBTB.js";
15
+ import {
16
+ getNormalizedOriginPath
17
+ } from "./chunk-256KIVJL.js";
18
+ import {
19
+ InvalidCsrfTokenError,
20
+ InvalidRedirectToError
21
+ } from "./chunk-FJUDBLCP.js";
22
+ import {
23
+ AuraResponse
24
+ } from "./chunk-JAPMIE6S.js";
8
25
 
9
26
  // src/actions/signOut/signOut.ts
10
- import z from "zod"
11
- import { createEndpoint, createEndpointConfig, statusCode } from "@aura-stack/router"
27
+ import z from "zod";
28
+ import { createEndpoint, createEndpointConfig, statusCode } from "@aura-stack/router";
12
29
  var config = createEndpointConfig({
13
- schemas: {
14
- searchParams: z.object({
15
- token_type_hint: z.literal("session_token"),
16
- redirectTo: z.string().optional(),
17
- }),
18
- },
19
- })
30
+ schemas: {
31
+ searchParams: z.object({
32
+ token_type_hint: z.literal("session_token"),
33
+ redirectTo: z.string().optional()
34
+ })
35
+ }
36
+ });
20
37
  var signOutAction = createEndpoint(
21
- "POST",
22
- "/signOut",
23
- async (ctx) => {
24
- const {
25
- request,
26
- headers,
27
- searchParams: { redirectTo },
28
- context: { cookies, jose, trustedProxyHeaders },
29
- } = ctx
30
- try {
31
- const cookiesOptions = secureCookieOptions(request, cookies, trustedProxyHeaders)
32
- const session = getCookie(request, "sessionToken", cookiesOptions)
33
- const csrfToken = getCookie(request, "csrfToken", {
34
- ...cookiesOptions,
35
- prefix: cookiesOptions.secure ? "__Host-" : "",
36
- })
37
- const header = headers.get("X-CSRF-Token")
38
- if (!header || !session || !csrfToken) {
39
- throw new Error("Missing CSRF token or session token")
40
- }
41
- await verifyCSRF(jose, csrfToken, header)
42
- await jose.decodeJWT(session)
43
- const normalizedOriginPath = getNormalizedOriginPath(request.url)
44
- const location = createRedirectTo(
45
- new Request(normalizedOriginPath, {
46
- headers,
47
- }),
48
- redirectTo
49
- )
50
- const responseHeaders = new Headers(cacheControl)
51
- responseHeaders.append("Set-Cookie", expireCookie("sessionToken", cookiesOptions))
52
- responseHeaders.append(
53
- "Set-Cookie",
54
- expireCookie("csrfToken", { ...cookiesOptions, prefix: cookiesOptions.secure ? "__Host-" : "" })
55
- )
56
- responseHeaders.append("Location", location)
57
- return Response.json(
58
- { message: "Signed out successfully" },
59
- { status: statusCode.ACCEPTED, headers: responseHeaders }
60
- )
61
- } catch (error) {
62
- if (error instanceof InvalidCsrfTokenError) {
63
- return AuraResponse.json(
64
- {
65
- error: "invalid_csrf_token",
66
- error_description: "The provided CSRF token is invalid or has expired",
67
- },
68
- { status: statusCode.UNAUTHORIZED }
69
- )
70
- }
71
- if (error instanceof InvalidRedirectToError) {
72
- const { type, message } = error
73
- return AuraResponse.json(
74
- {
75
- error: type,
76
- error_description: message,
77
- },
78
- { status: statusCode.BAD_REQUEST }
79
- )
80
- }
81
- return AuraResponse.json(
82
- {
83
- error: "invalid_session_token",
84
- error_description: "The provided sessionToken is invalid or has already expired",
85
- },
86
- { status: statusCode.UNAUTHORIZED }
87
- )
88
- }
89
- },
90
- config
91
- )
38
+ "POST",
39
+ "/signOut",
40
+ async (ctx) => {
41
+ const {
42
+ request,
43
+ headers,
44
+ searchParams: { redirectTo },
45
+ context: { cookies, jose, trustedProxyHeaders }
46
+ } = ctx;
47
+ try {
48
+ const cookiesOptions = secureCookieOptions(request, cookies, trustedProxyHeaders);
49
+ const session = getCookie(request, "sessionToken", cookiesOptions);
50
+ const csrfToken = getCookie(request, "csrfToken", {
51
+ ...cookiesOptions,
52
+ prefix: cookiesOptions.secure ? "__Host-" : ""
53
+ });
54
+ const header = headers.get("X-CSRF-Token");
55
+ if (!header || !session || !csrfToken) {
56
+ throw new Error("Missing CSRF token or session token");
57
+ }
58
+ await verifyCSRF(jose, csrfToken, header);
59
+ await jose.decodeJWT(session);
60
+ const normalizedOriginPath = getNormalizedOriginPath(request.url);
61
+ const location = createRedirectTo(
62
+ new Request(normalizedOriginPath, {
63
+ headers
64
+ }),
65
+ redirectTo
66
+ );
67
+ const responseHeaders = new Headers(cacheControl);
68
+ responseHeaders.append("Set-Cookie", expireCookie("sessionToken", cookiesOptions));
69
+ responseHeaders.append(
70
+ "Set-Cookie",
71
+ expireCookie("csrfToken", { ...cookiesOptions, prefix: cookiesOptions.secure ? "__Host-" : "" })
72
+ );
73
+ responseHeaders.append("Location", location);
74
+ return Response.json(
75
+ { message: "Signed out successfully" },
76
+ { status: statusCode.ACCEPTED, headers: responseHeaders }
77
+ );
78
+ } catch (error) {
79
+ if (error instanceof InvalidCsrfTokenError) {
80
+ return AuraResponse.json(
81
+ {
82
+ error: "invalid_csrf_token",
83
+ error_description: "The provided CSRF token is invalid or has expired"
84
+ },
85
+ { status: statusCode.UNAUTHORIZED }
86
+ );
87
+ }
88
+ if (error instanceof InvalidRedirectToError) {
89
+ const { type, message } = error;
90
+ return AuraResponse.json(
91
+ {
92
+ error: type,
93
+ error_description: message
94
+ },
95
+ { status: statusCode.BAD_REQUEST }
96
+ );
97
+ }
98
+ return AuraResponse.json(
99
+ {
100
+ error: "invalid_session_token",
101
+ error_description: "The provided sessionToken is invalid or has already expired"
102
+ },
103
+ { status: statusCode.UNAUTHORIZED }
104
+ );
105
+ }
106
+ },
107
+ config
108
+ );
92
109
 
93
- export { signOutAction }
110
+ export {
111
+ signOutAction
112
+ };
@@ -1,20 +1,30 @@
1
- import { getCookie, secureCookieOptions, setCookie } from "./chunk-ZV4BH47P.js"
2
- import { cacheControl } from "./chunk-STHEPPUZ.js"
3
- import { createCSRF } from "./chunk-GZU3RBTB.js"
1
+ import {
2
+ getCookie,
3
+ secureCookieOptions,
4
+ setCookie
5
+ } from "./chunk-ZV4BH47P.js";
6
+ import {
7
+ cacheControl
8
+ } from "./chunk-STHEPPUZ.js";
9
+ import {
10
+ createCSRF
11
+ } from "./chunk-GZU3RBTB.js";
4
12
 
5
13
  // src/actions/csrfToken/csrfToken.ts
6
- import { createEndpoint } from "@aura-stack/router"
14
+ import { createEndpoint } from "@aura-stack/router";
7
15
  var csrfTokenAction = createEndpoint("GET", "/csrfToken", async (ctx) => {
8
- const {
9
- request,
10
- context: { cookies, jose, trustedProxyHeaders },
11
- } = ctx
12
- const cookieOptions = secureCookieOptions(request, { ...cookies, strategy: "host" }, trustedProxyHeaders)
13
- const existingCSRFToken = getCookie(request, "csrfToken", cookieOptions, true)
14
- const csrfToken = await createCSRF(jose, existingCSRFToken)
15
- const headers = new Headers(cacheControl)
16
- headers.set("Set-Cookie", setCookie("csrfToken", csrfToken, cookieOptions))
17
- return Response.json({ csrfToken }, { headers })
18
- })
16
+ const {
17
+ request,
18
+ context: { cookies, jose, trustedProxyHeaders }
19
+ } = ctx;
20
+ const cookieOptions = secureCookieOptions(request, { ...cookies, strategy: "host" }, trustedProxyHeaders);
21
+ const existingCSRFToken = getCookie(request, "csrfToken", cookieOptions, true);
22
+ const csrfToken = await createCSRF(jose, existingCSRFToken);
23
+ const headers = new Headers(cacheControl);
24
+ headers.set("Set-Cookie", setCookie("csrfToken", csrfToken, cookieOptions));
25
+ return Response.json({ csrfToken }, { headers });
26
+ });
19
27
 
20
- export { csrfTokenAction }
28
+ export {
29
+ csrfTokenAction
30
+ };
@@ -1,9 +1,11 @@
1
1
  // src/headers.ts
2
2
  var cacheControl = {
3
- "Cache-Control": "no-store",
4
- Pragma: "no-cache",
5
- Expires: "0",
6
- Vary: "Cookie",
7
- }
3
+ "Cache-Control": "no-store",
4
+ Pragma: "no-cache",
5
+ Expires: "0",
6
+ Vary: "Cookie"
7
+ };
8
8
 
9
- export { cacheControl }
9
+ export {
10
+ cacheControl
11
+ };
@@ -1,42 +1,52 @@
1
- import { AuthError, ERROR_RESPONSE, throwAuthError } from "./chunk-FJUDBLCP.js"
2
- import { OAuthAccessToken, OAuthAccessTokenErrorResponse, OAuthAccessTokenResponse } from "./chunk-HMRKN75I.js"
1
+ import {
2
+ AuthError,
3
+ ERROR_RESPONSE,
4
+ throwAuthError
5
+ } from "./chunk-FJUDBLCP.js";
6
+ import {
7
+ OAuthAccessToken,
8
+ OAuthAccessTokenErrorResponse,
9
+ OAuthAccessTokenResponse
10
+ } from "./chunk-HMRKN75I.js";
3
11
 
4
12
  // src/actions/callback/access-token.ts
5
13
  var createAccessToken = async (oauthConfig, redirectURI, code, codeVerifier) => {
6
- const parsed = OAuthAccessToken.safeParse({ ...oauthConfig, redirectURI, code, codeVerifier })
7
- if (!parsed.success) {
8
- throw new AuthError(ERROR_RESPONSE.ACCESS_TOKEN.INVALID_REQUEST, "Invalid OAuth configuration")
14
+ const parsed = OAuthAccessToken.safeParse({ ...oauthConfig, redirectURI, code, codeVerifier });
15
+ if (!parsed.success) {
16
+ throw new AuthError(ERROR_RESPONSE.ACCESS_TOKEN.INVALID_REQUEST, "Invalid OAuth configuration");
17
+ }
18
+ const { accessToken, clientId, clientSecret, code: codeParsed, redirectURI: redirectParsed } = parsed.data;
19
+ try {
20
+ const response = await fetch(accessToken, {
21
+ method: "POST",
22
+ headers: {
23
+ Accept: "application/json",
24
+ "Content-Type": "application/x-www-form-urlencoded"
25
+ },
26
+ body: new URLSearchParams({
27
+ client_id: clientId,
28
+ client_secret: clientSecret,
29
+ code: codeParsed,
30
+ redirect_uri: redirectParsed,
31
+ grant_type: "authorization_code",
32
+ code_verifier: codeVerifier
33
+ }).toString()
34
+ });
35
+ const json = await response.json();
36
+ const token = OAuthAccessTokenResponse.safeParse(json);
37
+ if (!token.success) {
38
+ const { success, data } = OAuthAccessTokenErrorResponse.safeParse(json);
39
+ if (!success) {
40
+ throw new AuthError(ERROR_RESPONSE.ACCESS_TOKEN.INVALID_GRANT, "Invalid access token response format");
41
+ }
42
+ throw new AuthError(data.error, data?.error_description ?? "Failed to retrieve access token");
9
43
  }
10
- const { accessToken, clientId, clientSecret, code: codeParsed, redirectURI: redirectParsed } = parsed.data
11
- try {
12
- const response = await fetch(accessToken, {
13
- method: "POST",
14
- headers: {
15
- Accept: "application/json",
16
- "Content-Type": "application/x-www-form-urlencoded",
17
- },
18
- body: new URLSearchParams({
19
- client_id: clientId,
20
- client_secret: clientSecret,
21
- code: codeParsed,
22
- redirect_uri: redirectParsed,
23
- grant_type: "authorization_code",
24
- code_verifier: codeVerifier,
25
- }).toString(),
26
- })
27
- const json = await response.json()
28
- const token = OAuthAccessTokenResponse.safeParse(json)
29
- if (!token.success) {
30
- const { success, data } = OAuthAccessTokenErrorResponse.safeParse(json)
31
- if (!success) {
32
- throw new AuthError(ERROR_RESPONSE.ACCESS_TOKEN.INVALID_GRANT, "Invalid access token response format")
33
- }
34
- throw new AuthError(data.error, data?.error_description ?? "Failed to retrieve access token")
35
- }
36
- return token.data
37
- } catch (error) {
38
- throw throwAuthError(error, "Failed to create access token")
39
- }
40
- }
44
+ return token.data;
45
+ } catch (error) {
46
+ throw throwAuthError(error, "Failed to create access token");
47
+ }
48
+ };
41
49
 
42
- export { createAccessToken }
50
+ export {
51
+ createAccessToken
52
+ };
@@ -1,25 +1,31 @@
1
- import { createDerivedSalt } from "./chunk-GZU3RBTB.js"
2
- import { AuthError } from "./chunk-FJUDBLCP.js"
1
+ import {
2
+ createDerivedSalt
3
+ } from "./chunk-GZU3RBTB.js";
4
+ import {
5
+ AuthError
6
+ } from "./chunk-FJUDBLCP.js";
3
7
 
4
8
  // src/jose.ts
5
- import "dotenv/config"
6
- import { createJWT, createJWS, createDeriveKey } from "@aura-stack/jose"
9
+ import "dotenv/config";
10
+ import { createJWT, createJWS, createDeriveKey } from "@aura-stack/jose";
7
11
  var createJoseInstance = (secret) => {
8
- secret ?? (secret = process.env.AURA_AUTH_SECRET)
9
- if (!secret) {
10
- throw new AuthError("JOSE_INIT_ERROR", "AURA_AUTH_SECRET environment variable is not set and no secret was provided.")
11
- }
12
- const salt = process.env.AURA_AUTH_SALT ?? createDerivedSalt(secret)
13
- const { derivedKey: derivedSessionKey } = createDeriveKey(secret, salt, "session")
14
- const { derivedKey: derivedCsrfTokenKey } = createDeriveKey(secret, salt, "csrfToken")
15
- const { decodeJWT, encodeJWT } = createJWT(derivedSessionKey)
16
- const { signJWS, verifyJWS } = createJWS(derivedCsrfTokenKey)
17
- return {
18
- decodeJWT,
19
- encodeJWT,
20
- signJWS,
21
- verifyJWS,
22
- }
23
- }
12
+ secret ?? (secret = process.env.AURA_AUTH_SECRET);
13
+ if (!secret) {
14
+ throw new AuthError("JOSE_INIT_ERROR", "AURA_AUTH_SECRET environment variable is not set and no secret was provided.");
15
+ }
16
+ const salt = process.env.AURA_AUTH_SALT ?? createDerivedSalt(secret);
17
+ const { derivedKey: derivedSessionKey } = createDeriveKey(secret, salt, "session");
18
+ const { derivedKey: derivedCsrfTokenKey } = createDeriveKey(secret, salt, "csrfToken");
19
+ const { decodeJWT, encodeJWT } = createJWT(derivedSessionKey);
20
+ const { signJWS, verifyJWS } = createJWS(derivedCsrfTokenKey);
21
+ return {
22
+ decodeJWT,
23
+ encodeJWT,
24
+ signJWS,
25
+ verifyJWS
26
+ };
27
+ };
24
28
 
25
- export { createJoseInstance }
29
+ export {
30
+ createJoseInstance
31
+ };
@@ -1,44 +1,61 @@
1
- import { figma } from "./chunk-FKRDCWBF.js"
2
- import { github } from "./chunk-IKHPGFCW.js"
3
- import { gitlab } from "./chunk-KRNOMBXQ.js"
4
- import { spotify } from "./chunk-E3OXBRYF.js"
5
- import { x } from "./chunk-42XB3YCW.js"
6
- import { bitbucket } from "./chunk-FIPU4MLT.js"
7
- import { discord } from "./chunk-EBPE35JT.js"
1
+ import {
2
+ figma
3
+ } from "./chunk-FKRDCWBF.js";
4
+ import {
5
+ github
6
+ } from "./chunk-IKHPGFCW.js";
7
+ import {
8
+ gitlab
9
+ } from "./chunk-KRNOMBXQ.js";
10
+ import {
11
+ spotify
12
+ } from "./chunk-E3OXBRYF.js";
13
+ import {
14
+ x
15
+ } from "./chunk-42XB3YCW.js";
16
+ import {
17
+ bitbucket
18
+ } from "./chunk-FIPU4MLT.js";
19
+ import {
20
+ discord
21
+ } from "./chunk-EBPE35JT.js";
8
22
 
9
23
  // src/oauth/index.ts
10
24
  var builtInOAuthProviders = {
11
- github,
12
- bitbucket,
13
- figma,
14
- discord,
15
- gitlab,
16
- spotify,
17
- x,
18
- }
25
+ github,
26
+ bitbucket,
27
+ figma,
28
+ discord,
29
+ gitlab,
30
+ spotify,
31
+ x
32
+ };
19
33
  var defineOAuthEnvironment = (oauth) => {
20
- const env = process.env
21
- return {
22
- clientId: env[`AURA_AUTH_${oauth.toUpperCase()}_CLIENT_ID`],
23
- clientSecret: env[`AURA_AUTH_${oauth.toUpperCase()}_CLIENT_SECRET`],
24
- }
25
- }
34
+ const env = process.env;
35
+ return {
36
+ clientId: env[`AURA_AUTH_${oauth.toUpperCase()}_CLIENT_ID`],
37
+ clientSecret: env[`AURA_AUTH_${oauth.toUpperCase()}_CLIENT_SECRET`]
38
+ };
39
+ };
26
40
  var defineOAuthProviderConfig = (config) => {
27
- if (typeof config === "string") {
28
- const definition = defineOAuthEnvironment(config)
29
- const oauthConfig = builtInOAuthProviders[config]
30
- return {
31
- ...oauthConfig,
32
- ...definition,
33
- }
34
- }
35
- return config
36
- }
41
+ if (typeof config === "string") {
42
+ const definition = defineOAuthEnvironment(config);
43
+ const oauthConfig = builtInOAuthProviders[config];
44
+ return {
45
+ ...oauthConfig,
46
+ ...definition
47
+ };
48
+ }
49
+ return config;
50
+ };
37
51
  var createBuiltInOAuthProviders = (oauth = []) => {
38
- return oauth.reduce((previous, config) => {
39
- const oauthConfig = defineOAuthProviderConfig(config)
40
- return { ...previous, [oauthConfig.id]: oauthConfig }
41
- }, {})
42
- }
52
+ return oauth.reduce((previous, config) => {
53
+ const oauthConfig = defineOAuthProviderConfig(config);
54
+ return { ...previous, [oauthConfig.id]: oauthConfig };
55
+ }, {});
56
+ };
43
57
 
44
- export { builtInOAuthProviders, createBuiltInOAuthProviders }
58
+ export {
59
+ builtInOAuthProviders,
60
+ createBuiltInOAuthProviders
61
+ };
@@ -1,27 +1,37 @@
1
- import { expireCookie, getCookie, secureCookieOptions } from "./chunk-ZV4BH47P.js"
2
- import { cacheControl } from "./chunk-STHEPPUZ.js"
3
- import { toISOString } from "./chunk-256KIVJL.js"
1
+ import {
2
+ expireCookie,
3
+ getCookie,
4
+ secureCookieOptions
5
+ } from "./chunk-ZV4BH47P.js";
6
+ import {
7
+ cacheControl
8
+ } from "./chunk-STHEPPUZ.js";
9
+ import {
10
+ toISOString
11
+ } from "./chunk-256KIVJL.js";
4
12
 
5
13
  // src/actions/session/session.ts
6
- import { createEndpoint } from "@aura-stack/router"
14
+ import { createEndpoint } from "@aura-stack/router";
7
15
  var sessionAction = createEndpoint("GET", "/session", async (ctx) => {
8
- const {
9
- request,
10
- context: { cookies, jose, trustedProxyHeaders },
11
- } = ctx
12
- const cookieOptions = secureCookieOptions(request, cookies, trustedProxyHeaders)
13
- try {
14
- const session = getCookie(request, "sessionToken", cookieOptions)
15
- const decoded = await jose.decodeJWT(session)
16
- const { exp, iat, jti, nbf, ...user } = decoded
17
- const headers = new Headers(cacheControl)
18
- return Response.json({ user, expires: toISOString(exp * 1e3) }, { headers })
19
- } catch {
20
- const headers = new Headers(cacheControl)
21
- const sessionCookie = expireCookie("sessionToken", cookieOptions)
22
- headers.set("Set-Cookie", sessionCookie)
23
- return Response.json({ authenticated: false, message: "Unauthorized" }, { status: 401, headers })
24
- }
25
- })
16
+ const {
17
+ request,
18
+ context: { cookies, jose, trustedProxyHeaders }
19
+ } = ctx;
20
+ const cookieOptions = secureCookieOptions(request, cookies, trustedProxyHeaders);
21
+ try {
22
+ const session = getCookie(request, "sessionToken", cookieOptions);
23
+ const decoded = await jose.decodeJWT(session);
24
+ const { exp, iat, jti, nbf, ...user } = decoded;
25
+ const headers = new Headers(cacheControl);
26
+ return Response.json({ user, expires: toISOString(exp * 1e3) }, { headers });
27
+ } catch {
28
+ const headers = new Headers(cacheControl);
29
+ const sessionCookie = expireCookie("sessionToken", cookieOptions);
30
+ headers.set("Set-Cookie", sessionCookie);
31
+ return Response.json({ authenticated: false, message: "Unauthorized" }, { status: 401, headers });
32
+ }
33
+ });
26
34
 
27
- export { sessionAction }
35
+ export {
36
+ sessionAction
37
+ };