@aura-stack/auth 0.4.0-rc.5 → 0.5.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.
- package/dist/@types/index.d.ts +8 -3
- package/dist/@types/router.d.cjs +0 -17
- package/dist/@types/router.d.d.ts +7 -2
- package/dist/@types/router.d.js +0 -1
- package/dist/actions/callback/access-token.cjs +130 -71
- package/dist/actions/callback/access-token.d.ts +9 -4
- package/dist/actions/callback/access-token.js +3 -4
- package/dist/actions/callback/callback.cjs +428 -152
- package/dist/actions/callback/callback.d.ts +11 -3
- package/dist/actions/callback/callback.js +12 -10
- package/dist/actions/callback/userinfo.cjs +159 -65
- package/dist/actions/callback/userinfo.d.ts +8 -3
- package/dist/actions/callback/userinfo.js +7 -6
- package/dist/actions/csrfToken/csrfToken.cjs +70 -19
- package/dist/actions/csrfToken/csrfToken.js +8 -7
- package/dist/actions/index.cjs +780 -348
- package/dist/actions/index.d.ts +6 -2
- package/dist/actions/index.js +23 -18
- package/dist/actions/session/session.cjs +107 -26
- package/dist/actions/session/session.js +7 -5
- package/dist/actions/signIn/authorization-url.cjs +288 -0
- package/dist/actions/signIn/authorization-url.d.ts +31 -0
- package/dist/actions/signIn/authorization-url.js +16 -0
- package/dist/actions/signIn/authorization.cjs +209 -211
- package/dist/actions/signIn/authorization.d.ts +32 -21
- package/dist/actions/signIn/authorization.js +12 -9
- package/dist/actions/signIn/signIn.cjs +470 -235
- package/dist/actions/signIn/signIn.d.ts +12 -3
- package/dist/actions/signIn/signIn.js +11 -8
- package/dist/actions/signOut/signOut.cjs +376 -228
- package/dist/actions/signOut/signOut.d.ts +1 -1
- package/dist/actions/signOut/signOut.js +10 -9
- package/dist/api/createApi.cjs +750 -0
- package/dist/api/createApi.d.ts +12 -0
- package/dist/api/createApi.js +19 -0
- package/dist/api/getSession.cjs +141 -0
- package/dist/api/getSession.d.ts +16 -0
- package/dist/api/getSession.js +10 -0
- package/dist/api/signIn.cjs +549 -0
- package/dist/api/signIn.d.ts +26 -0
- package/dist/api/signIn.js +15 -0
- package/dist/api/signOut.cjs +279 -0
- package/dist/api/signOut.d.ts +16 -0
- package/dist/api/signOut.js +13 -0
- package/dist/assert.cjs +150 -5
- package/dist/assert.d.ts +26 -3
- package/dist/assert.js +17 -3
- package/dist/{chunk-YRCB5FLE.js → chunk-2A5B7GWR.js} +52 -6
- package/dist/chunk-2GQLSIJ2.js +40 -0
- package/dist/chunk-2IR674WX.js +44 -0
- package/dist/chunk-3J5TUH2I.js +50 -0
- package/dist/chunk-4RWSYUKX.js +98 -0
- package/dist/chunk-4YHJ4IEQ.js +25 -0
- package/dist/chunk-54CZPKR4.js +25 -0
- package/dist/chunk-5LZ7TOM3.js +25 -0
- package/dist/chunk-7BE46WWS.js +88 -0
- package/dist/chunk-7YYXFKLR.js +35 -0
- package/dist/chunk-C3A37LQC.js +33 -0
- package/dist/chunk-CITNGXDA.js +31 -0
- package/dist/chunk-CWX724AG.js +78 -0
- package/dist/chunk-D2CSIUKP.js +74 -0
- package/dist/chunk-E6G5YCI6.js +25 -0
- package/dist/chunk-EBAMFRB7.js +34 -0
- package/dist/chunk-EEE7UM5T.js +25 -0
- package/dist/{chunk-HT4YLL7N.js → chunk-FPCVZUVG.js} +10 -8
- package/dist/chunk-FW4W3REU.js +25 -0
- package/dist/chunk-GNNBM2WJ.js +83 -0
- package/dist/chunk-IPKO6UQN.js +25 -0
- package/dist/chunk-JOCGX3RP.js +59 -0
- package/dist/chunk-KBXWTD6E.js +94 -0
- package/dist/chunk-KMMAZFSJ.js +25 -0
- package/dist/chunk-LATR3NIV.js +117 -0
- package/dist/chunk-LAYPUDQF.js +39 -0
- package/dist/chunk-LDU7A2JE.js +25 -0
- package/dist/chunk-LX3TJ2TJ.js +294 -0
- package/dist/chunk-NHZBQNRR.js +143 -0
- package/dist/chunk-OVHNRULD.js +33 -0
- package/dist/chunk-PDP3PHB3.js +127 -0
- package/dist/chunk-PHYNROD4.js +47 -0
- package/dist/chunk-QQEKY4XP.js +29 -0
- package/dist/chunk-U4RK4LKJ.js +348 -0
- package/dist/{chunk-RRLIF4PQ.js → chunk-U5663F2U.js} +16 -1
- package/dist/chunk-UN7X6SU5.js +53 -0
- package/dist/chunk-UZQJJD6A.js +100 -0
- package/dist/chunk-V6LLEAR4.js +80 -0
- package/dist/chunk-WHNDRO3N.js +50 -0
- package/dist/{chunk-W6LG7BFW.js → chunk-XY5R3EHH.js} +30 -23
- package/dist/client/client.cjs +135 -0
- package/dist/client/client.d.ts +85 -0
- package/dist/client/client.js +9 -0
- package/dist/client/index.cjs +135 -0
- package/dist/client/index.d.ts +14 -0
- package/dist/client/index.js +10 -0
- package/dist/context.cjs +1237 -0
- package/dist/context.d.ts +16 -0
- package/dist/context.js +28 -0
- package/dist/cookie.cjs +57 -22
- package/dist/cookie.d.ts +11 -6
- package/dist/cookie.js +3 -2
- package/dist/createAuth.cjs +2320 -0
- package/dist/createAuth.d.ts +12 -0
- package/dist/createAuth.js +48 -0
- package/dist/env.cjs +78 -0
- package/dist/env.d.ts +10 -0
- package/dist/env.js +12 -0
- package/dist/errors.cjs +17 -0
- package/dist/errors.d.ts +15 -4
- package/dist/errors.js +5 -1
- package/dist/headers.cjs +28 -2
- package/dist/headers.d.ts +25 -1
- package/dist/headers.js +9 -3
- package/dist/index-_aXtxb_s.d.ts +1377 -0
- package/dist/index.cjs +1843 -610
- package/dist/index.d.ts +11 -92
- package/dist/index.js +53 -85
- package/dist/jose.cjs +113 -38
- package/dist/jose.d.ts +12 -23
- package/dist/jose.js +17 -7
- package/dist/logger.cjs +424 -0
- package/dist/logger.d.ts +12 -0
- package/dist/logger.js +17 -0
- package/dist/oauth/atlassian.cjs +57 -0
- package/dist/oauth/atlassian.d.ts +12 -0
- package/dist/oauth/atlassian.js +6 -0
- package/dist/oauth/bitbucket.cjs +19 -15
- package/dist/oauth/bitbucket.d.ts +7 -2
- package/dist/oauth/bitbucket.js +1 -1
- package/dist/oauth/discord.cjs +27 -24
- package/dist/oauth/discord.d.ts +7 -2
- package/dist/oauth/discord.js +1 -1
- package/dist/oauth/dropbox.cjs +53 -0
- package/dist/oauth/dropbox.d.ts +12 -0
- package/dist/oauth/dropbox.js +6 -0
- package/dist/oauth/figma.cjs +19 -16
- package/dist/oauth/figma.d.ts +7 -2
- package/dist/oauth/figma.js +1 -1
- package/dist/oauth/github.cjs +19 -8
- package/dist/oauth/github.d.ts +7 -2
- package/dist/oauth/github.js +1 -1
- package/dist/oauth/gitlab.cjs +19 -16
- package/dist/oauth/gitlab.d.ts +7 -2
- package/dist/oauth/gitlab.js +1 -1
- package/dist/oauth/index.cjs +529 -239
- package/dist/oauth/index.d.ts +7 -2
- package/dist/oauth/index.js +39 -22
- package/dist/oauth/mailchimp.cjs +19 -16
- package/dist/oauth/mailchimp.d.ts +7 -2
- package/dist/oauth/mailchimp.js +1 -1
- package/dist/oauth/notion.cjs +131 -0
- package/dist/oauth/notion.d.ts +12 -0
- package/dist/oauth/notion.js +9 -0
- package/dist/oauth/pinterest.cjs +19 -16
- package/dist/oauth/pinterest.d.ts +7 -2
- package/dist/oauth/pinterest.js +1 -1
- package/dist/oauth/spotify.cjs +19 -16
- package/dist/oauth/spotify.d.ts +7 -2
- package/dist/oauth/spotify.js +1 -1
- package/dist/oauth/strava.cjs +19 -16
- package/dist/oauth/strava.d.ts +7 -2
- package/dist/oauth/strava.js +1 -1
- package/dist/oauth/twitch.cjs +95 -0
- package/dist/oauth/twitch.d.ts +12 -0
- package/dist/oauth/twitch.js +7 -0
- package/dist/oauth/x.cjs +19 -16
- package/dist/oauth/x.d.ts +7 -2
- package/dist/oauth/x.js +1 -1
- package/dist/schemas.cjs +89 -42
- package/dist/schemas.d.ts +114 -18
- package/dist/schemas.js +5 -3
- package/dist/secure.cjs +73 -31
- package/dist/secure.d.ts +11 -11
- package/dist/secure.js +7 -6
- package/dist/utils.cjs +203 -90
- package/dist/utils.d.ts +21 -40
- package/dist/utils.js +21 -12
- package/package.json +9 -6
- package/dist/chunk-3EUWD5BB.js +0 -63
- package/dist/chunk-42XB3YCW.js +0 -22
- package/dist/chunk-6R2YZ4AC.js +0 -22
- package/dist/chunk-A3N4PVAT.js +0 -70
- package/dist/chunk-B737EUJV.js +0 -22
- package/dist/chunk-CXLATHS5.js +0 -143
- package/dist/chunk-E3OXBRYF.js +0 -22
- package/dist/chunk-EIL2FPSS.js +0 -22
- package/dist/chunk-EMKJA2GJ.js +0 -89
- package/dist/chunk-FIPU4MLT.js +0 -21
- package/dist/chunk-FKRDCWBF.js +0 -22
- package/dist/chunk-GA2SMTJO.js +0 -58
- package/dist/chunk-HP34YGGJ.js +0 -22
- package/dist/chunk-IKHPGFCW.js +0 -14
- package/dist/chunk-IUYZQTJV.js +0 -30
- package/dist/chunk-IVET23KF.js +0 -58
- package/dist/chunk-JVFTCTTE.js +0 -33
- package/dist/chunk-KRNOMBXQ.js +0 -22
- package/dist/chunk-KSWLO5ZU.js +0 -102
- package/dist/chunk-N2APGLXA.js +0 -71
- package/dist/chunk-N4SX7TZT.js +0 -96
- package/dist/chunk-STHEPPUZ.js +0 -11
- package/dist/chunk-TLE4PXY3.js +0 -39
- package/dist/index-B8jeIElf.d.ts +0 -679
- /package/dist/{chunk-DIVDFNAP.js → chunk-5X7JZMEF.js} +0 -0
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import {
|
|
2
|
+
env
|
|
3
|
+
} from "./chunk-WHNDRO3N.js";
|
|
1
4
|
import {
|
|
2
5
|
AuthInternalError
|
|
3
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-U5663F2U.js";
|
|
4
7
|
|
|
5
8
|
// src/cookie.ts
|
|
6
9
|
import { parse, parseSetCookie, serialize } from "@aura-stack/router/cookie";
|
|
@@ -37,10 +40,11 @@ var setCookie = (cookieName, value, options) => {
|
|
|
37
40
|
var expiredCookieAttributes = {
|
|
38
41
|
...defaultCookieOptions,
|
|
39
42
|
expires: /* @__PURE__ */ new Date(0),
|
|
40
|
-
maxAge: 0
|
|
43
|
+
maxAge: 0,
|
|
44
|
+
secure: true
|
|
41
45
|
};
|
|
42
46
|
var getCookie = (request, cookieName) => {
|
|
43
|
-
const cookies = request.headers.get("Cookie");
|
|
47
|
+
const cookies = request instanceof Request ? request.headers.get("Cookie") : request.get("Cookie");
|
|
44
48
|
if (!cookies) {
|
|
45
49
|
throw new AuthInternalError("COOKIE_NOT_FOUND", "No cookies found. There is no active session");
|
|
46
50
|
}
|
|
@@ -69,31 +73,27 @@ var createSessionCookie = async (jose, session) => {
|
|
|
69
73
|
throw new AuthInternalError("INVALID_JWT_TOKEN", "Failed to create session cookie", { cause: error });
|
|
70
74
|
}
|
|
71
75
|
};
|
|
72
|
-
var defineSecureCookieOptions = (useSecure, attributes, strategy) => {
|
|
76
|
+
var defineSecureCookieOptions = (useSecure, attributes, strategy, logger) => {
|
|
73
77
|
if (!attributes.httpOnly) {
|
|
74
|
-
|
|
75
|
-
"[WARNING]: Cookie is configured without HttpOnly. This allows JavaScript access via document.cookie and increases XSS risk."
|
|
76
|
-
);
|
|
78
|
+
logger?.log("COOKIE_HTTPONLY_DISABLED");
|
|
77
79
|
}
|
|
78
80
|
if (attributes.domain === "*") {
|
|
79
81
|
attributes.domain = void 0;
|
|
80
|
-
|
|
82
|
+
logger?.log("COOKIE_WILDCARD_DOMAIN");
|
|
81
83
|
}
|
|
82
84
|
if (!useSecure) {
|
|
83
85
|
if (attributes.secure) {
|
|
84
|
-
|
|
85
|
-
"[WARNING]: The 'Secure' attribute will be disabled for this cookie. Serve over HTTPS to enforce Secure cookies."
|
|
86
|
-
);
|
|
86
|
+
logger?.log("COOKIE_SECURE_DISABLED");
|
|
87
87
|
}
|
|
88
88
|
if (attributes.sameSite == "none") {
|
|
89
89
|
attributes.sameSite = "lax";
|
|
90
|
-
|
|
90
|
+
logger?.log("COOKIE_SAMESITE_NONE_WITHOUT_SECURE");
|
|
91
91
|
}
|
|
92
|
-
if (
|
|
93
|
-
|
|
92
|
+
if (env.NODE_ENV === "production") {
|
|
93
|
+
logger?.log("COOKIE_INSECURE_IN_PRODUCTION");
|
|
94
94
|
}
|
|
95
95
|
if (strategy === "host") {
|
|
96
|
-
|
|
96
|
+
logger?.log("COOKIE_HOST_STRATEGY_INSECURE");
|
|
97
97
|
}
|
|
98
98
|
return {
|
|
99
99
|
...defaultCookieOptions,
|
|
@@ -107,7 +107,7 @@ var defineSecureCookieOptions = (useSecure, attributes, strategy) => {
|
|
|
107
107
|
...defaultHostCookieConfig
|
|
108
108
|
} : { ...defaultCookieOptions, ...attributes, ...defaultSecureCookieConfig };
|
|
109
109
|
};
|
|
110
|
-
var createCookieStore = (useSecure, prefix, overrides) => {
|
|
110
|
+
var createCookieStore = (useSecure, prefix, overrides, logger) => {
|
|
111
111
|
prefix ??= COOKIE_NAME;
|
|
112
112
|
const securePrefix = useSecure ? "__Secure-" : "";
|
|
113
113
|
const hostPrefix = useSecure ? "__Host-" : "";
|
|
@@ -120,7 +120,8 @@ var createCookieStore = (useSecure, prefix, overrides) => {
|
|
|
120
120
|
...defaultCookieOptions,
|
|
121
121
|
...overrides?.sessionToken?.attributes
|
|
122
122
|
},
|
|
123
|
-
overrides?.sessionToken?.attributes?.strategy ?? "secure"
|
|
123
|
+
overrides?.sessionToken?.attributes?.strategy ?? "secure",
|
|
124
|
+
logger
|
|
124
125
|
)
|
|
125
126
|
},
|
|
126
127
|
state: {
|
|
@@ -131,7 +132,8 @@ var createCookieStore = (useSecure, prefix, overrides) => {
|
|
|
131
132
|
...oauthCookieOptions,
|
|
132
133
|
...overrides?.state?.attributes
|
|
133
134
|
},
|
|
134
|
-
overrides?.state?.attributes?.strategy ?? "secure"
|
|
135
|
+
overrides?.state?.attributes?.strategy ?? "secure",
|
|
136
|
+
logger
|
|
135
137
|
)
|
|
136
138
|
},
|
|
137
139
|
csrfToken: {
|
|
@@ -140,9 +142,11 @@ var createCookieStore = (useSecure, prefix, overrides) => {
|
|
|
140
142
|
useSecure,
|
|
141
143
|
{
|
|
142
144
|
...overrides?.csrfToken?.attributes,
|
|
143
|
-
...defaultHostCookieConfig
|
|
145
|
+
...defaultHostCookieConfig,
|
|
146
|
+
sameSite: "strict"
|
|
144
147
|
},
|
|
145
|
-
overrides?.csrfToken?.attributes?.strategy ?? "host"
|
|
148
|
+
overrides?.csrfToken?.attributes?.strategy ?? "host",
|
|
149
|
+
logger
|
|
146
150
|
)
|
|
147
151
|
},
|
|
148
152
|
redirectTo: {
|
|
@@ -153,7 +157,8 @@ var createCookieStore = (useSecure, prefix, overrides) => {
|
|
|
153
157
|
...oauthCookieOptions,
|
|
154
158
|
...overrides?.redirectTo?.attributes
|
|
155
159
|
},
|
|
156
|
-
overrides?.redirectTo?.attributes?.strategy ?? "secure"
|
|
160
|
+
overrides?.redirectTo?.attributes?.strategy ?? "secure",
|
|
161
|
+
logger
|
|
157
162
|
)
|
|
158
163
|
},
|
|
159
164
|
redirectURI: {
|
|
@@ -164,7 +169,8 @@ var createCookieStore = (useSecure, prefix, overrides) => {
|
|
|
164
169
|
...oauthCookieOptions,
|
|
165
170
|
...overrides?.redirectURI?.attributes
|
|
166
171
|
},
|
|
167
|
-
overrides?.redirectURI?.attributes?.strategy ?? "secure"
|
|
172
|
+
overrides?.redirectURI?.attributes?.strategy ?? "secure",
|
|
173
|
+
logger
|
|
168
174
|
)
|
|
169
175
|
},
|
|
170
176
|
codeVerifier: {
|
|
@@ -175,7 +181,8 @@ var createCookieStore = (useSecure, prefix, overrides) => {
|
|
|
175
181
|
...oauthCookieOptions,
|
|
176
182
|
...overrides?.codeVerifier?.attributes
|
|
177
183
|
},
|
|
178
|
-
overrides?.codeVerifier?.attributes?.strategy ?? "secure"
|
|
184
|
+
overrides?.codeVerifier?.attributes?.strategy ?? "secure",
|
|
185
|
+
logger
|
|
179
186
|
)
|
|
180
187
|
}
|
|
181
188
|
};
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/client/client.ts
|
|
21
|
+
var client_exports = {};
|
|
22
|
+
__export(client_exports, {
|
|
23
|
+
createAuthClient: () => createAuthClient,
|
|
24
|
+
createClient: () => createClient
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(client_exports);
|
|
27
|
+
|
|
28
|
+
// src/errors.ts
|
|
29
|
+
var AuthClientError = class extends Error {
|
|
30
|
+
type = "AUTH_CLIENT_ERROR";
|
|
31
|
+
code;
|
|
32
|
+
constructor(code, message, options) {
|
|
33
|
+
super(message, options);
|
|
34
|
+
this.code = code;
|
|
35
|
+
this.name = new.target.name;
|
|
36
|
+
Error.captureStackTrace(this, new.target);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
var isNativeError = (error) => {
|
|
40
|
+
return error instanceof Error;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// src/client/client.ts
|
|
44
|
+
var import_router = require("@aura-stack/router");
|
|
45
|
+
var createClient = import_router.createClient;
|
|
46
|
+
var createAuthClient = (options) => {
|
|
47
|
+
if (typeof window === "undefined" && !options.baseURL) {
|
|
48
|
+
throw new AuthClientError("`baseURL` is required when createAuthClient is used outside the browser.");
|
|
49
|
+
}
|
|
50
|
+
const client = createClient({
|
|
51
|
+
cache: "no-store",
|
|
52
|
+
credentials: "include",
|
|
53
|
+
baseURL: options.baseURL ?? window.location.origin,
|
|
54
|
+
...options
|
|
55
|
+
});
|
|
56
|
+
const getCSRFToken = async () => {
|
|
57
|
+
try {
|
|
58
|
+
const response = await client.get("/csrfToken");
|
|
59
|
+
if (!response.ok) return null;
|
|
60
|
+
const data = await response.json();
|
|
61
|
+
return data.csrfToken;
|
|
62
|
+
} catch (error) {
|
|
63
|
+
console.error("Error fetching CSRF token:", error);
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const getSession = async () => {
|
|
68
|
+
try {
|
|
69
|
+
const response = await client.get("/session");
|
|
70
|
+
if (!response.ok) return null;
|
|
71
|
+
const session = await response.json();
|
|
72
|
+
if (!session?.authenticated) return null;
|
|
73
|
+
return session.session;
|
|
74
|
+
} catch (error) {
|
|
75
|
+
console.error("Error fetching session:", error);
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const signIn = async (oauth, options2) => {
|
|
80
|
+
try {
|
|
81
|
+
const response = await client.get("/signIn/:oauth", {
|
|
82
|
+
params: {
|
|
83
|
+
oauth
|
|
84
|
+
},
|
|
85
|
+
searchParams: {
|
|
86
|
+
...options2,
|
|
87
|
+
redirect: false
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
const json = await response.json();
|
|
91
|
+
if ((options2?.redirect ?? true) && typeof window !== "undefined" && json?.signInURL) {
|
|
92
|
+
window.location.assign(json.signInURL);
|
|
93
|
+
}
|
|
94
|
+
return json;
|
|
95
|
+
} catch (error) {
|
|
96
|
+
console.error("Error during sign-in:", error);
|
|
97
|
+
return { redirect: false, signInURL: "/" };
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
const signOut = async (options2) => {
|
|
101
|
+
try {
|
|
102
|
+
const csrfToken = await getCSRFToken();
|
|
103
|
+
if (!csrfToken) {
|
|
104
|
+
throw new AuthClientError("Failed to fetch CSRF token for sign-out.");
|
|
105
|
+
}
|
|
106
|
+
const response = await client.post("/signOut", {
|
|
107
|
+
searchParams: {
|
|
108
|
+
redirectTo: options2?.redirectTo ?? "/",
|
|
109
|
+
token_type_hint: "session_token"
|
|
110
|
+
},
|
|
111
|
+
headers: {
|
|
112
|
+
"X-CSRF-Token": csrfToken
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
const json = await response.json();
|
|
116
|
+
if ((options2?.redirect ?? true) && typeof window !== "undefined" && json?.url) {
|
|
117
|
+
window.location.assign(json.url);
|
|
118
|
+
}
|
|
119
|
+
return json;
|
|
120
|
+
} catch (error) {
|
|
121
|
+
console.error("Error during sign-out:", error);
|
|
122
|
+
throw isNativeError(error) ? error : new AuthClientError("Sign-out failed.", "The sign-out request failed.", { cause: error });
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
return {
|
|
126
|
+
getSession,
|
|
127
|
+
signIn,
|
|
128
|
+
signOut
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
132
|
+
0 && (module.exports = {
|
|
133
|
+
createAuthClient,
|
|
134
|
+
createClient
|
|
135
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { l as AuthClientOptions, m as Session, B as BuiltInOAuthProvider, n as SignInOptions, o as SignOutOptions } from '../index-_aXtxb_s.js';
|
|
2
|
+
import '@aura-stack/router/types';
|
|
3
|
+
import * as zod_v4_core from 'zod/v4/core';
|
|
4
|
+
import * as zod from 'zod';
|
|
5
|
+
import * as _aura_stack_router from '@aura-stack/router';
|
|
6
|
+
import { LiteralUnion } from '../@types/utility.js';
|
|
7
|
+
import '../schemas.js';
|
|
8
|
+
import 'zod/v4';
|
|
9
|
+
import '@aura-stack/jose';
|
|
10
|
+
import '@aura-stack/jose/jose';
|
|
11
|
+
import '@aura-stack/jose/crypto';
|
|
12
|
+
import '@aura-stack/router/cookie';
|
|
13
|
+
import 'jose';
|
|
14
|
+
|
|
15
|
+
declare const createClient: (options: _aura_stack_router.ClientOptions) => _aura_stack_router.Client<[_aura_stack_router.RouteEndpoint<"GET", "/signIn/:oauth", {
|
|
16
|
+
schemas?: {
|
|
17
|
+
params: zod.ZodObject<{
|
|
18
|
+
oauth: zod.ZodEnum<{
|
|
19
|
+
[x: string & Record<never, never>]: string & Record<never, never>;
|
|
20
|
+
github: "github";
|
|
21
|
+
bitbucket: "bitbucket";
|
|
22
|
+
figma: "figma";
|
|
23
|
+
discord: "discord";
|
|
24
|
+
gitlab: "gitlab";
|
|
25
|
+
spotify: "spotify";
|
|
26
|
+
x: "x";
|
|
27
|
+
strava: "strava";
|
|
28
|
+
mailchimp: "mailchimp";
|
|
29
|
+
pinterest: "pinterest";
|
|
30
|
+
twitch: "twitch";
|
|
31
|
+
notion: "notion";
|
|
32
|
+
dropbox: "dropbox";
|
|
33
|
+
atlassian: "atlassian";
|
|
34
|
+
}>;
|
|
35
|
+
}, zod_v4_core.$strip>;
|
|
36
|
+
searchParams: zod.ZodObject<{
|
|
37
|
+
redirect: zod.ZodDefault<zod.ZodOptional<zod.ZodCodec<zod.ZodString, zod.ZodBoolean>>>;
|
|
38
|
+
redirectTo: zod.ZodOptional<zod.ZodString>;
|
|
39
|
+
}, zod_v4_core.$strip>;
|
|
40
|
+
} | undefined;
|
|
41
|
+
}>, _aura_stack_router.RouteEndpoint<"GET", "/callback/:oauth", {
|
|
42
|
+
schemas?: {
|
|
43
|
+
params: zod.ZodObject<{
|
|
44
|
+
oauth: zod.ZodEnum<{
|
|
45
|
+
[x: string & Record<never, never>]: string & Record<never, never>;
|
|
46
|
+
github: "github";
|
|
47
|
+
bitbucket: "bitbucket";
|
|
48
|
+
figma: "figma";
|
|
49
|
+
discord: "discord";
|
|
50
|
+
gitlab: "gitlab";
|
|
51
|
+
spotify: "spotify";
|
|
52
|
+
x: "x";
|
|
53
|
+
strava: "strava";
|
|
54
|
+
mailchimp: "mailchimp";
|
|
55
|
+
pinterest: "pinterest";
|
|
56
|
+
twitch: "twitch";
|
|
57
|
+
notion: "notion";
|
|
58
|
+
dropbox: "dropbox";
|
|
59
|
+
atlassian: "atlassian";
|
|
60
|
+
}>;
|
|
61
|
+
}, zod_v4_core.$strip>;
|
|
62
|
+
searchParams: zod.ZodObject<{
|
|
63
|
+
code: zod.ZodString;
|
|
64
|
+
state: zod.ZodString;
|
|
65
|
+
}, zod_v4_core.$strip>;
|
|
66
|
+
} | undefined;
|
|
67
|
+
}>, _aura_stack_router.RouteEndpoint<"GET", "/session", {
|
|
68
|
+
schemas?: _aura_stack_router.EndpointSchemas | undefined;
|
|
69
|
+
}>, _aura_stack_router.RouteEndpoint<"POST", "/signOut", {
|
|
70
|
+
schemas?: {
|
|
71
|
+
searchParams: zod.ZodObject<{
|
|
72
|
+
token_type_hint: zod.ZodLiteral<"session_token">;
|
|
73
|
+
redirectTo: zod.ZodOptional<zod.ZodString>;
|
|
74
|
+
}, zod_v4_core.$strip>;
|
|
75
|
+
} | undefined;
|
|
76
|
+
}>, _aura_stack_router.RouteEndpoint<"GET", "/csrfToken", {
|
|
77
|
+
schemas?: _aura_stack_router.EndpointSchemas | undefined;
|
|
78
|
+
}>]>;
|
|
79
|
+
declare const createAuthClient: (options: AuthClientOptions) => {
|
|
80
|
+
getSession: () => Promise<Session | null>;
|
|
81
|
+
signIn: (oauth: LiteralUnion<BuiltInOAuthProvider>, options?: SignInOptions) => Promise<any>;
|
|
82
|
+
signOut: (options?: SignOutOptions) => Promise<any>;
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
export { createAuthClient, createClient };
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/client/index.ts
|
|
21
|
+
var client_exports = {};
|
|
22
|
+
__export(client_exports, {
|
|
23
|
+
createAuthClient: () => createAuthClient,
|
|
24
|
+
createClient: () => createClient
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(client_exports);
|
|
27
|
+
|
|
28
|
+
// src/errors.ts
|
|
29
|
+
var AuthClientError = class extends Error {
|
|
30
|
+
type = "AUTH_CLIENT_ERROR";
|
|
31
|
+
code;
|
|
32
|
+
constructor(code, message, options) {
|
|
33
|
+
super(message, options);
|
|
34
|
+
this.code = code;
|
|
35
|
+
this.name = new.target.name;
|
|
36
|
+
Error.captureStackTrace(this, new.target);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
var isNativeError = (error) => {
|
|
40
|
+
return error instanceof Error;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// src/client/client.ts
|
|
44
|
+
var import_router = require("@aura-stack/router");
|
|
45
|
+
var createClient = import_router.createClient;
|
|
46
|
+
var createAuthClient = (options) => {
|
|
47
|
+
if (typeof window === "undefined" && !options.baseURL) {
|
|
48
|
+
throw new AuthClientError("`baseURL` is required when createAuthClient is used outside the browser.");
|
|
49
|
+
}
|
|
50
|
+
const client = createClient({
|
|
51
|
+
cache: "no-store",
|
|
52
|
+
credentials: "include",
|
|
53
|
+
baseURL: options.baseURL ?? window.location.origin,
|
|
54
|
+
...options
|
|
55
|
+
});
|
|
56
|
+
const getCSRFToken = async () => {
|
|
57
|
+
try {
|
|
58
|
+
const response = await client.get("/csrfToken");
|
|
59
|
+
if (!response.ok) return null;
|
|
60
|
+
const data = await response.json();
|
|
61
|
+
return data.csrfToken;
|
|
62
|
+
} catch (error) {
|
|
63
|
+
console.error("Error fetching CSRF token:", error);
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const getSession = async () => {
|
|
68
|
+
try {
|
|
69
|
+
const response = await client.get("/session");
|
|
70
|
+
if (!response.ok) return null;
|
|
71
|
+
const session = await response.json();
|
|
72
|
+
if (!session?.authenticated) return null;
|
|
73
|
+
return session.session;
|
|
74
|
+
} catch (error) {
|
|
75
|
+
console.error("Error fetching session:", error);
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const signIn = async (oauth, options2) => {
|
|
80
|
+
try {
|
|
81
|
+
const response = await client.get("/signIn/:oauth", {
|
|
82
|
+
params: {
|
|
83
|
+
oauth
|
|
84
|
+
},
|
|
85
|
+
searchParams: {
|
|
86
|
+
...options2,
|
|
87
|
+
redirect: false
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
const json = await response.json();
|
|
91
|
+
if ((options2?.redirect ?? true) && typeof window !== "undefined" && json?.signInURL) {
|
|
92
|
+
window.location.assign(json.signInURL);
|
|
93
|
+
}
|
|
94
|
+
return json;
|
|
95
|
+
} catch (error) {
|
|
96
|
+
console.error("Error during sign-in:", error);
|
|
97
|
+
return { redirect: false, signInURL: "/" };
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
const signOut = async (options2) => {
|
|
101
|
+
try {
|
|
102
|
+
const csrfToken = await getCSRFToken();
|
|
103
|
+
if (!csrfToken) {
|
|
104
|
+
throw new AuthClientError("Failed to fetch CSRF token for sign-out.");
|
|
105
|
+
}
|
|
106
|
+
const response = await client.post("/signOut", {
|
|
107
|
+
searchParams: {
|
|
108
|
+
redirectTo: options2?.redirectTo ?? "/",
|
|
109
|
+
token_type_hint: "session_token"
|
|
110
|
+
},
|
|
111
|
+
headers: {
|
|
112
|
+
"X-CSRF-Token": csrfToken
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
const json = await response.json();
|
|
116
|
+
if ((options2?.redirect ?? true) && typeof window !== "undefined" && json?.url) {
|
|
117
|
+
window.location.assign(json.url);
|
|
118
|
+
}
|
|
119
|
+
return json;
|
|
120
|
+
} catch (error) {
|
|
121
|
+
console.error("Error during sign-out:", error);
|
|
122
|
+
throw isNativeError(error) ? error : new AuthClientError("Sign-out failed.", "The sign-out request failed.", { cause: error });
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
return {
|
|
126
|
+
getSession,
|
|
127
|
+
signIn,
|
|
128
|
+
signOut
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
132
|
+
0 && (module.exports = {
|
|
133
|
+
createAuthClient,
|
|
134
|
+
createClient
|
|
135
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { createAuthClient, createClient } from './client.js';
|
|
2
|
+
export { p as AuthClient, l as AuthClientOptions, n as SignInOptions, o as SignOutOptions } from '../index-_aXtxb_s.js';
|
|
3
|
+
export { Client, ClientOptions } from '@aura-stack/router/types';
|
|
4
|
+
import 'zod/v4/core';
|
|
5
|
+
import 'zod';
|
|
6
|
+
import '@aura-stack/router';
|
|
7
|
+
import '../@types/utility.js';
|
|
8
|
+
import '../schemas.js';
|
|
9
|
+
import 'zod/v4';
|
|
10
|
+
import '@aura-stack/jose';
|
|
11
|
+
import '@aura-stack/jose/jose';
|
|
12
|
+
import '@aura-stack/jose/crypto';
|
|
13
|
+
import '@aura-stack/router/cookie';
|
|
14
|
+
import 'jose';
|