create-croissant 0.1.1 → 0.1.2
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 +2 -2
- package/template/apps/web/node_modules/@better-auth/core/dist/api/index.mjs +29 -3
- package/template/apps/web/node_modules/@better-auth/core/dist/context/global.mjs +1 -1
- package/template/apps/web/node_modules/@better-auth/core/dist/db/adapter/factory.mjs +1 -1
- package/template/apps/web/node_modules/@better-auth/core/dist/instrumentation/api.mjs +1 -31
- package/template/apps/web/node_modules/@better-auth/core/dist/instrumentation/noop.mjs +42 -0
- package/template/apps/web/node_modules/@better-auth/core/dist/instrumentation/pure.index.d.mts +7 -0
- package/template/apps/web/node_modules/@better-auth/core/dist/instrumentation/pure.index.mjs +7 -0
- package/template/apps/web/node_modules/@better-auth/core/dist/instrumentation/tracer.mjs +1 -1
- package/template/apps/web/node_modules/@better-auth/core/dist/oauth2/index.d.mts +2 -2
- package/template/apps/web/node_modules/@better-auth/core/dist/oauth2/index.mjs +2 -2
- package/template/apps/web/node_modules/@better-auth/core/dist/oauth2/utils.d.mts +10 -1
- package/template/apps/web/node_modules/@better-auth/core/dist/oauth2/utils.mjs +13 -1
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/apple.d.mts +11 -2
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/apple.mjs +7 -1
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/atlassian.mjs +1 -1
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/cognito.d.mts +1 -1
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/cognito.mjs +3 -2
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/facebook.d.mts +1 -1
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/facebook.mjs +7 -0
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/figma.mjs +1 -1
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/google.d.mts +1 -1
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/google.mjs +3 -2
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/microsoft-entra-id.d.mts +2 -2
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/microsoft-entra-id.mjs +6 -1
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/paybin.mjs +1 -1
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/paypal.mjs +1 -1
- package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/salesforce.mjs +1 -1
- package/template/apps/web/node_modules/@better-auth/core/dist/utils/is-api-error.d.mts +6 -0
- package/template/apps/web/node_modules/@better-auth/core/dist/utils/is-api-error.mjs +8 -0
- package/template/apps/web/node_modules/@better-auth/core/package.json +7 -1
- package/template/apps/web/node_modules/@better-auth/core/src/api/index.ts +39 -5
- package/template/apps/web/node_modules/@better-auth/core/src/instrumentation/api.ts +2 -49
- package/template/apps/web/node_modules/@better-auth/core/src/instrumentation/noop.ts +74 -0
- package/template/apps/web/node_modules/@better-auth/core/src/instrumentation/pure.index.ts +31 -0
- package/template/apps/web/node_modules/@better-auth/core/src/oauth2/index.ts +5 -1
- package/template/apps/web/node_modules/@better-auth/core/src/oauth2/utils.ts +13 -0
- package/template/apps/web/node_modules/@better-auth/core/src/social-providers/apple.ts +10 -2
- package/template/apps/web/node_modules/@better-auth/core/src/social-providers/cognito.ts +3 -2
- package/template/apps/web/node_modules/@better-auth/core/src/social-providers/facebook.ts +10 -1
- package/template/apps/web/node_modules/@better-auth/core/src/social-providers/google.ts +3 -2
- package/template/apps/web/node_modules/@better-auth/core/src/social-providers/microsoft-entra-id.ts +13 -3
- package/template/apps/web/node_modules/@better-auth/core/src/utils/is-api-error.ts +10 -0
- package/template/apps/web/node_modules/@better-auth/drizzle-adapter/package.json +3 -3
- package/template/apps/web/package.json +4 -4
- package/template/apps/web/src/components/app-sidebar.tsx +77 -121
- package/template/apps/web/src/routeTree.gen.ts +112 -1
- package/template/apps/web/src/routes/__root.tsx +13 -1
- package/template/apps/web/src/routes/client-orpc-auth.tsx +62 -0
- package/template/apps/web/src/routes/client-orpc.tsx +43 -0
- package/template/apps/web/src/routes/isr.tsx +33 -0
- package/template/apps/web/src/routes/ssr-orpc-auth.tsx +53 -0
- package/template/apps/web/src/routes/ssr-orpc.tsx +36 -0
- package/template/package.json +2 -2
- package/template/packages/auth/package.json +1 -1
- package/template/packages/orpc/package.json +2 -4
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "0.1.
|
|
6
|
+
"version": "0.1.2",
|
|
7
7
|
"description": "Scaffold a new project using the Croissant Stack",
|
|
8
8
|
"repository": {
|
|
9
9
|
"type": "git",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"execa": "^9.3.0",
|
|
33
33
|
"fs-extra": "^11.2.0",
|
|
34
34
|
"inquirer": "^13.4.2",
|
|
35
|
-
"ora": "^9.
|
|
35
|
+
"ora": "^9.4.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/fs-extra": "^11.0.4",
|
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
import { runWithEndpointContext } from "../context/endpoint-context.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { isAPIError } from "../utils/is-api-error.mjs";
|
|
3
|
+
import { createEndpoint, createMiddleware, kAPIErrorHeaderSymbol } from "better-call";
|
|
3
4
|
//#region src/api/index.ts
|
|
5
|
+
/**
|
|
6
|
+
* Better-call's createEndpoint re-throws APIError without exposing the headers
|
|
7
|
+
* accumulated on ctx.responseHeaders (e.g. Set-Cookie from deleteSessionCookie
|
|
8
|
+
* before throw). Attach them to the error via kAPIErrorHeaderSymbol — matching
|
|
9
|
+
* better-call's createMiddleware contract so the outer pipeline can merge them
|
|
10
|
+
* into the response.
|
|
11
|
+
*/
|
|
12
|
+
function attachResponseHeadersToAPIError(responseHeaders, e) {
|
|
13
|
+
if (!isAPIError(e) || !responseHeaders) return;
|
|
14
|
+
Object.defineProperty(e, kAPIErrorHeaderSymbol, {
|
|
15
|
+
enumerable: false,
|
|
16
|
+
configurable: true,
|
|
17
|
+
value: responseHeaders,
|
|
18
|
+
writable: false
|
|
19
|
+
});
|
|
20
|
+
}
|
|
4
21
|
const optionsMiddleware = createMiddleware(async () => {
|
|
5
22
|
/**
|
|
6
23
|
* This will be passed on the instance of
|
|
@@ -17,14 +34,23 @@ function createAuthEndpoint(pathOrOptions, handlerOrOptions, handlerOrNever) {
|
|
|
17
34
|
const path = typeof pathOrOptions === "string" ? pathOrOptions : void 0;
|
|
18
35
|
const options = typeof handlerOrOptions === "object" ? handlerOrOptions : pathOrOptions;
|
|
19
36
|
const handler = typeof handlerOrOptions === "function" ? handlerOrOptions : handlerOrNever;
|
|
37
|
+
const wrapped = async (ctx) => {
|
|
38
|
+
const runtimeCtx = ctx;
|
|
39
|
+
try {
|
|
40
|
+
return await runWithEndpointContext(ctx, () => handler(ctx));
|
|
41
|
+
} catch (e) {
|
|
42
|
+
attachResponseHeadersToAPIError(runtimeCtx.responseHeaders, e);
|
|
43
|
+
throw e;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
20
46
|
if (path) return createEndpoint(path, {
|
|
21
47
|
...options,
|
|
22
48
|
use: [...options?.use || [], ...use]
|
|
23
|
-
},
|
|
49
|
+
}, wrapped);
|
|
24
50
|
return createEndpoint({
|
|
25
51
|
...options,
|
|
26
52
|
use: [...options?.use || [], ...use]
|
|
27
|
-
},
|
|
53
|
+
}, wrapped);
|
|
28
54
|
}
|
|
29
55
|
//#endregion
|
|
30
56
|
export { createAuthEndpoint, createAuthMiddleware, optionsMiddleware };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { BetterAuthError } from "../../error/index.mjs";
|
|
1
2
|
import { getAuthTables } from "../get-tables.mjs";
|
|
2
3
|
import { getColorDepth } from "../../env/color-depth.mjs";
|
|
3
4
|
import { TTY_COLORS, createLogger } from "../../env/logger.mjs";
|
|
4
|
-
import { BetterAuthError } from "../../error/index.mjs";
|
|
5
5
|
import { ATTR_DB_COLLECTION_NAME, ATTR_DB_OPERATION_NAME } from "../../instrumentation/attributes.mjs";
|
|
6
6
|
import { withSpan } from "../../instrumentation/tracer.mjs";
|
|
7
7
|
import { safeJSONParse } from "../../utils/json.mjs";
|
|
@@ -1,35 +1,5 @@
|
|
|
1
|
+
import { noopOpenTelemetryAPI } from "./noop.mjs";
|
|
1
2
|
//#region src/instrumentation/api.ts
|
|
2
|
-
function createNoopSpan() {
|
|
3
|
-
return {
|
|
4
|
-
end() {},
|
|
5
|
-
setAttribute(_key, _value) {},
|
|
6
|
-
setStatus(_status) {},
|
|
7
|
-
recordException(_exception) {}
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
function createNoopTracer(noopSpanInstance) {
|
|
11
|
-
function startActiveSpan(_name, _options, fn) {
|
|
12
|
-
return fn(noopSpanInstance);
|
|
13
|
-
}
|
|
14
|
-
return { startActiveSpan };
|
|
15
|
-
}
|
|
16
|
-
function createNoopTraceAPI() {
|
|
17
|
-
const noopTracer = createNoopTracer(createNoopSpan());
|
|
18
|
-
return { getTracer(_name, _version) {
|
|
19
|
-
return noopTracer;
|
|
20
|
-
} };
|
|
21
|
-
}
|
|
22
|
-
function createNoopOpenTelemetryAPI() {
|
|
23
|
-
return {
|
|
24
|
-
SpanStatusCode: {
|
|
25
|
-
UNSET: 0,
|
|
26
|
-
OK: 1,
|
|
27
|
-
ERROR: 2
|
|
28
|
-
},
|
|
29
|
-
trace: createNoopTraceAPI()
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
const noopOpenTelemetryAPI = createNoopOpenTelemetryAPI();
|
|
33
3
|
let openTelemetryAPIPromise;
|
|
34
4
|
let openTelemetryAPI;
|
|
35
5
|
function getOpenTelemetryAPI() {
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
//#region src/instrumentation/noop.ts
|
|
2
|
+
function createNoopSpan() {
|
|
3
|
+
const span = {
|
|
4
|
+
end() {},
|
|
5
|
+
setAttribute(_key, _value) {},
|
|
6
|
+
setStatus(_status) {},
|
|
7
|
+
recordException(_exception) {},
|
|
8
|
+
updateName(_name) {
|
|
9
|
+
return span;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
return span;
|
|
13
|
+
}
|
|
14
|
+
function createNoopTracer(noopSpan) {
|
|
15
|
+
function startActiveSpan(_name, ...rest) {
|
|
16
|
+
const fn = rest[rest.length - 1];
|
|
17
|
+
return fn(noopSpan);
|
|
18
|
+
}
|
|
19
|
+
return { startActiveSpan };
|
|
20
|
+
}
|
|
21
|
+
function createNoopTraceAPI() {
|
|
22
|
+
const noopTracer = createNoopTracer(createNoopSpan());
|
|
23
|
+
return {
|
|
24
|
+
getTracer(_name, _version) {
|
|
25
|
+
return noopTracer;
|
|
26
|
+
},
|
|
27
|
+
getActiveSpan() {}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
function createNoopOpenTelemetryAPI() {
|
|
31
|
+
return {
|
|
32
|
+
SpanStatusCode: {
|
|
33
|
+
UNSET: 0,
|
|
34
|
+
OK: 1,
|
|
35
|
+
ERROR: 2
|
|
36
|
+
},
|
|
37
|
+
trace: createNoopTraceAPI()
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const noopOpenTelemetryAPI = createNoopOpenTelemetryAPI();
|
|
41
|
+
//#endregion
|
|
42
|
+
export { noopOpenTelemetryAPI };
|
package/template/apps/web/node_modules/@better-auth/core/dist/instrumentation/pure.index.d.mts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ATTR_CONTEXT, ATTR_DB_COLLECTION_NAME, ATTR_DB_OPERATION_NAME, ATTR_HOOK_TYPE, ATTR_HTTP_RESPONSE_STATUS_CODE, ATTR_HTTP_ROUTE, ATTR_OPERATION_ID } from "./attributes.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/instrumentation/pure.index.d.ts
|
|
4
|
+
declare function withSpan<T>(name: string, attributes: Record<string, string | number | boolean>, fn: () => T): T;
|
|
5
|
+
declare function withSpan<T>(name: string, attributes: Record<string, string | number | boolean>, fn: () => Promise<T>): Promise<T>;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { ATTR_CONTEXT, ATTR_DB_COLLECTION_NAME, ATTR_DB_OPERATION_NAME, ATTR_HOOK_TYPE, ATTR_HTTP_RESPONSE_STATUS_CODE, ATTR_HTTP_ROUTE, ATTR_OPERATION_ID, withSpan };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ATTR_CONTEXT, ATTR_DB_COLLECTION_NAME, ATTR_DB_OPERATION_NAME, ATTR_HOOK_TYPE, ATTR_HTTP_RESPONSE_STATUS_CODE, ATTR_HTTP_ROUTE, ATTR_OPERATION_ID } from "./attributes.mjs";
|
|
2
|
+
//#region src/instrumentation/pure.index.ts
|
|
3
|
+
function withSpan(_name, _attributes, fn) {
|
|
4
|
+
return fn();
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
7
|
+
export { ATTR_CONTEXT, ATTR_DB_COLLECTION_NAME, ATTR_DB_OPERATION_NAME, ATTR_HOOK_TYPE, ATTR_HTTP_RESPONSE_STATUS_CODE, ATTR_HTTP_ROUTE, ATTR_OPERATION_ID, withSpan };
|
|
@@ -2,7 +2,7 @@ import { ATTR_HTTP_RESPONSE_STATUS_CODE } from "./attributes.mjs";
|
|
|
2
2
|
import { getOpenTelemetryAPI } from "./api.mjs";
|
|
3
3
|
//#region src/instrumentation/tracer.ts
|
|
4
4
|
const INSTRUMENTATION_SCOPE = "better-auth";
|
|
5
|
-
const INSTRUMENTATION_VERSION = "1.6.
|
|
5
|
+
const INSTRUMENTATION_VERSION = "1.6.7";
|
|
6
6
|
/**
|
|
7
7
|
* Better-auth uses `throw ctx.redirect(url)` for flow control (e.g. OAuth
|
|
8
8
|
* callbacks). These are APIErrors with 3xx status codes and should not be
|
|
@@ -2,7 +2,7 @@ import { OAuth2Tokens, OAuth2UserInfo, OAuthProvider, ProviderOptions } from "./
|
|
|
2
2
|
import { clientCredentialsToken, clientCredentialsTokenRequest, createClientCredentialsTokenRequest } from "./client-credentials-token.mjs";
|
|
3
3
|
import { createAuthorizationURL } from "./create-authorization-url.mjs";
|
|
4
4
|
import { createRefreshAccessTokenRequest, refreshAccessToken, refreshAccessTokenRequest } from "./refresh-access-token.mjs";
|
|
5
|
-
import { generateCodeChallenge, getOAuth2Tokens } from "./utils.mjs";
|
|
5
|
+
import { generateCodeChallenge, getOAuth2Tokens, getPrimaryClientId } from "./utils.mjs";
|
|
6
6
|
import { authorizationCodeRequest, createAuthorizationCodeRequest, validateAuthorizationCode, validateToken } from "./validate-authorization-code.mjs";
|
|
7
7
|
import { getJwks, verifyAccessToken, verifyJwsAccessToken } from "./verify.mjs";
|
|
8
|
-
export { type OAuth2Tokens, type OAuth2UserInfo, type OAuthProvider, type ProviderOptions, authorizationCodeRequest, clientCredentialsToken, clientCredentialsTokenRequest, createAuthorizationCodeRequest, createAuthorizationURL, createClientCredentialsTokenRequest, createRefreshAccessTokenRequest, generateCodeChallenge, getJwks, getOAuth2Tokens, refreshAccessToken, refreshAccessTokenRequest, validateAuthorizationCode, validateToken, verifyAccessToken, verifyJwsAccessToken };
|
|
8
|
+
export { type OAuth2Tokens, type OAuth2UserInfo, type OAuthProvider, type ProviderOptions, authorizationCodeRequest, clientCredentialsToken, clientCredentialsTokenRequest, createAuthorizationCodeRequest, createAuthorizationURL, createClientCredentialsTokenRequest, createRefreshAccessTokenRequest, generateCodeChallenge, getJwks, getOAuth2Tokens, getPrimaryClientId, refreshAccessToken, refreshAccessTokenRequest, validateAuthorizationCode, validateToken, verifyAccessToken, verifyJwsAccessToken };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { clientCredentialsToken, clientCredentialsTokenRequest, createClientCredentialsTokenRequest } from "./client-credentials-token.mjs";
|
|
2
|
-
import { generateCodeChallenge, getOAuth2Tokens } from "./utils.mjs";
|
|
2
|
+
import { generateCodeChallenge, getOAuth2Tokens, getPrimaryClientId } from "./utils.mjs";
|
|
3
3
|
import { createAuthorizationURL } from "./create-authorization-url.mjs";
|
|
4
4
|
import { createRefreshAccessTokenRequest, refreshAccessToken, refreshAccessTokenRequest } from "./refresh-access-token.mjs";
|
|
5
5
|
import { authorizationCodeRequest, createAuthorizationCodeRequest, validateAuthorizationCode, validateToken } from "./validate-authorization-code.mjs";
|
|
6
6
|
import { getJwks, verifyAccessToken, verifyJwsAccessToken } from "./verify.mjs";
|
|
7
|
-
export { authorizationCodeRequest, clientCredentialsToken, clientCredentialsTokenRequest, createAuthorizationCodeRequest, createAuthorizationURL, createClientCredentialsTokenRequest, createRefreshAccessTokenRequest, generateCodeChallenge, getJwks, getOAuth2Tokens, refreshAccessToken, refreshAccessTokenRequest, validateAuthorizationCode, validateToken, verifyAccessToken, verifyJwsAccessToken };
|
|
7
|
+
export { authorizationCodeRequest, clientCredentialsToken, clientCredentialsTokenRequest, createAuthorizationCodeRequest, createAuthorizationURL, createClientCredentialsTokenRequest, createRefreshAccessTokenRequest, generateCodeChallenge, getJwks, getOAuth2Tokens, getPrimaryClientId, refreshAccessToken, refreshAccessTokenRequest, validateAuthorizationCode, validateToken, verifyAccessToken, verifyJwsAccessToken };
|
|
@@ -2,6 +2,15 @@ import { OAuth2Tokens } from "./oauth-provider.mjs";
|
|
|
2
2
|
|
|
3
3
|
//#region src/oauth2/utils.d.ts
|
|
4
4
|
declare function getOAuth2Tokens(data: Record<string, any>): OAuth2Tokens;
|
|
5
|
+
/**
|
|
6
|
+
* Return the provider's primary Client ID: the single string, or the entry at
|
|
7
|
+
* array index 0 for the cross-platform form used by ID token audience
|
|
8
|
+
* verification. Index 0 is the designated primary and pairs with
|
|
9
|
+
* `clientSecret` for the authorization code flow; later array entries are
|
|
10
|
+
* only used as additional accepted audiences. Returns `undefined` when the
|
|
11
|
+
* primary value is missing or an empty string.
|
|
12
|
+
*/
|
|
13
|
+
declare function getPrimaryClientId(clientId: unknown): string | undefined;
|
|
5
14
|
declare function generateCodeChallenge(codeVerifier: string): Promise<string>;
|
|
6
15
|
//#endregion
|
|
7
|
-
export { generateCodeChallenge, getOAuth2Tokens };
|
|
16
|
+
export { generateCodeChallenge, getOAuth2Tokens, getPrimaryClientId };
|
|
@@ -16,10 +16,22 @@ function getOAuth2Tokens(data) {
|
|
|
16
16
|
raw: data
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Return the provider's primary Client ID: the single string, or the entry at
|
|
21
|
+
* array index 0 for the cross-platform form used by ID token audience
|
|
22
|
+
* verification. Index 0 is the designated primary and pairs with
|
|
23
|
+
* `clientSecret` for the authorization code flow; later array entries are
|
|
24
|
+
* only used as additional accepted audiences. Returns `undefined` when the
|
|
25
|
+
* primary value is missing or an empty string.
|
|
26
|
+
*/
|
|
27
|
+
function getPrimaryClientId(clientId) {
|
|
28
|
+
const value = Array.isArray(clientId) ? clientId[0] : clientId;
|
|
29
|
+
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
30
|
+
}
|
|
19
31
|
async function generateCodeChallenge(codeVerifier) {
|
|
20
32
|
const data = new TextEncoder().encode(codeVerifier);
|
|
21
33
|
const hash = await crypto.subtle.digest("SHA-256", data);
|
|
22
34
|
return base64Url.encode(new Uint8Array(hash), { padding: false });
|
|
23
35
|
}
|
|
24
36
|
//#endregion
|
|
25
|
-
export { generateCodeChallenge, getOAuth2Tokens };
|
|
37
|
+
export { generateCodeChallenge, getOAuth2Tokens, getPrimaryClientId };
|
|
@@ -60,7 +60,7 @@ interface AppleNonConformUser {
|
|
|
60
60
|
email: string;
|
|
61
61
|
}
|
|
62
62
|
interface AppleOptions extends ProviderOptions<AppleProfile> {
|
|
63
|
-
clientId: string;
|
|
63
|
+
clientId: string | string[];
|
|
64
64
|
appBundleIdentifier?: string | undefined;
|
|
65
65
|
audience?: (string | string[]) | undefined;
|
|
66
66
|
}
|
|
@@ -93,7 +93,16 @@ declare const apple: (options: AppleOptions) => {
|
|
|
93
93
|
refreshAccessToken: (refreshToken: string) => Promise<OAuth2Tokens>;
|
|
94
94
|
getUserInfo(token: OAuth2Tokens & {
|
|
95
95
|
user?: {
|
|
96
|
-
name
|
|
96
|
+
name?
|
|
97
|
+
/**
|
|
98
|
+
* An Integer value that indicates whether the user appears to be a real
|
|
99
|
+
* person. Use the value of this claim to mitigate fraud. The possible
|
|
100
|
+
* values are: 0 (or Unsupported), 1 (or Unknown), 2 (or LikelyReal). For
|
|
101
|
+
* more information, see ASUserDetectionStatus. This claim is present only
|
|
102
|
+
* in iOS 14 and later, macOS 11 and later, watchOS 7 and later, tvOS 14
|
|
103
|
+
* and later. The claim isn’t present or supported for web-based apps.
|
|
104
|
+
*/
|
|
105
|
+
: {
|
|
97
106
|
firstName?: string;
|
|
98
107
|
lastName?: string;
|
|
99
108
|
};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { APIError } from "../error/index.mjs";
|
|
1
|
+
import { APIError, BetterAuthError } from "../error/index.mjs";
|
|
2
|
+
import { logger } from "../env/logger.mjs";
|
|
3
|
+
import { getPrimaryClientId } from "../oauth2/utils.mjs";
|
|
2
4
|
import { createAuthorizationURL } from "../oauth2/create-authorization-url.mjs";
|
|
3
5
|
import { refreshAccessToken } from "../oauth2/refresh-access-token.mjs";
|
|
4
6
|
import { validateAuthorizationCode } from "../oauth2/validate-authorization-code.mjs";
|
|
@@ -11,6 +13,10 @@ const apple = (options) => {
|
|
|
11
13
|
id: "apple",
|
|
12
14
|
name: "Apple",
|
|
13
15
|
async createAuthorizationURL({ state, scopes, redirectURI }) {
|
|
16
|
+
if (!getPrimaryClientId(options.clientId) || !options.clientSecret) {
|
|
17
|
+
logger.error("Client ID and client secret are required for Apple. Make sure to provide them in the options.");
|
|
18
|
+
throw new BetterAuthError("CLIENT_ID_AND_SECRET_REQUIRED");
|
|
19
|
+
}
|
|
14
20
|
const _scope = options.disableDefaultScope ? [] : ["email", "name"];
|
|
15
21
|
if (options.scope) _scope.push(...options.scope);
|
|
16
22
|
if (scopes) _scope.push(...scopes);
|
package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/atlassian.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { logger } from "../env/logger.mjs";
|
|
2
1
|
import { BetterAuthError } from "../error/index.mjs";
|
|
2
|
+
import { logger } from "../env/logger.mjs";
|
|
3
3
|
import { createAuthorizationURL } from "../oauth2/create-authorization-url.mjs";
|
|
4
4
|
import { refreshAccessToken } from "../oauth2/refresh-access-token.mjs";
|
|
5
5
|
import { validateAuthorizationCode } from "../oauth2/validate-authorization-code.mjs";
|
package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/cognito.d.mts
CHANGED
|
@@ -19,7 +19,7 @@ interface CognitoProfile {
|
|
|
19
19
|
[key: string]: any;
|
|
20
20
|
}
|
|
21
21
|
interface CognitoOptions extends ProviderOptions<CognitoProfile> {
|
|
22
|
-
clientId: string;
|
|
22
|
+
clientId: string | string[];
|
|
23
23
|
/**
|
|
24
24
|
* The Cognito domain (e.g., "your-app.auth.us-east-1.amazoncognito.com")
|
|
25
25
|
*/
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { logger } from "../env/logger.mjs";
|
|
2
1
|
import { APIError, BetterAuthError } from "../error/index.mjs";
|
|
2
|
+
import { logger } from "../env/logger.mjs";
|
|
3
|
+
import { getPrimaryClientId } from "../oauth2/utils.mjs";
|
|
3
4
|
import { createAuthorizationURL } from "../oauth2/create-authorization-url.mjs";
|
|
4
5
|
import { refreshAccessToken } from "../oauth2/refresh-access-token.mjs";
|
|
5
6
|
import { validateAuthorizationCode } from "../oauth2/validate-authorization-code.mjs";
|
|
@@ -19,7 +20,7 @@ const cognito = (options) => {
|
|
|
19
20
|
id: "cognito",
|
|
20
21
|
name: "Cognito",
|
|
21
22
|
async createAuthorizationURL({ state, scopes, codeVerifier, redirectURI }) {
|
|
22
|
-
if (!options.clientId) {
|
|
23
|
+
if (!getPrimaryClientId(options.clientId)) {
|
|
23
24
|
logger.error("ClientId is required for Amazon Cognito. Make sure to provide them in the options.");
|
|
24
25
|
throw new BetterAuthError("CLIENT_ID_AND_SECRET_REQUIRED");
|
|
25
26
|
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { BetterAuthError } from "../error/index.mjs";
|
|
2
|
+
import { logger } from "../env/logger.mjs";
|
|
3
|
+
import { getPrimaryClientId } from "../oauth2/utils.mjs";
|
|
1
4
|
import { createAuthorizationURL } from "../oauth2/create-authorization-url.mjs";
|
|
2
5
|
import { refreshAccessToken } from "../oauth2/refresh-access-token.mjs";
|
|
3
6
|
import { validateAuthorizationCode } from "../oauth2/validate-authorization-code.mjs";
|
|
@@ -9,6 +12,10 @@ const facebook = (options) => {
|
|
|
9
12
|
id: "facebook",
|
|
10
13
|
name: "Facebook",
|
|
11
14
|
async createAuthorizationURL({ state, scopes, redirectURI, loginHint }) {
|
|
15
|
+
if (!getPrimaryClientId(options.clientId) || !options.clientSecret) {
|
|
16
|
+
logger.error("Client ID and client secret are required for Facebook. Make sure to provide them in the options.");
|
|
17
|
+
throw new BetterAuthError("CLIENT_ID_AND_SECRET_REQUIRED");
|
|
18
|
+
}
|
|
12
19
|
const _scopes = options.disableDefaultScope ? [] : ["email", "public_profile"];
|
|
13
20
|
if (options.scope) _scopes.push(...options.scope);
|
|
14
21
|
if (scopes) _scopes.push(...scopes);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { logger } from "../env/logger.mjs";
|
|
2
1
|
import { BetterAuthError } from "../error/index.mjs";
|
|
2
|
+
import { logger } from "../env/logger.mjs";
|
|
3
3
|
import { createAuthorizationURL } from "../oauth2/create-authorization-url.mjs";
|
|
4
4
|
import { refreshAccessToken } from "../oauth2/refresh-access-token.mjs";
|
|
5
5
|
import { validateAuthorizationCode } from "../oauth2/validate-authorization-code.mjs";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { logger } from "../env/logger.mjs";
|
|
2
1
|
import { APIError, BetterAuthError } from "../error/index.mjs";
|
|
2
|
+
import { logger } from "../env/logger.mjs";
|
|
3
|
+
import { getPrimaryClientId } from "../oauth2/utils.mjs";
|
|
3
4
|
import { createAuthorizationURL } from "../oauth2/create-authorization-url.mjs";
|
|
4
5
|
import { refreshAccessToken } from "../oauth2/refresh-access-token.mjs";
|
|
5
6
|
import { validateAuthorizationCode } from "../oauth2/validate-authorization-code.mjs";
|
|
@@ -11,7 +12,7 @@ const google = (options) => {
|
|
|
11
12
|
id: "google",
|
|
12
13
|
name: "Google",
|
|
13
14
|
async createAuthorizationURL({ state, scopes, codeVerifier, redirectURI, loginHint, display }) {
|
|
14
|
-
if (!options.clientId || !options.clientSecret) {
|
|
15
|
+
if (!getPrimaryClientId(options.clientId) || !options.clientSecret) {
|
|
15
16
|
logger.error("Client Id and Client Secret is required for Google. Make sure to provide them in the options.");
|
|
16
17
|
throw new BetterAuthError("CLIENT_ID_AND_SECRET_REQUIRED");
|
|
17
18
|
}
|
|
@@ -104,7 +104,7 @@ interface MicrosoftEntraIDProfile extends Record<string, any> {
|
|
|
104
104
|
given_name: string;
|
|
105
105
|
}
|
|
106
106
|
interface MicrosoftOptions extends ProviderOptions<MicrosoftEntraIDProfile> {
|
|
107
|
-
clientId: string;
|
|
107
|
+
clientId: string | string[];
|
|
108
108
|
/**
|
|
109
109
|
* The tenant ID of the Microsoft account
|
|
110
110
|
* @default "common"
|
|
@@ -151,7 +151,7 @@ declare const microsoft: (options: MicrosoftOptions) => {
|
|
|
151
151
|
user?: {
|
|
152
152
|
name?: {
|
|
153
153
|
firstName?: string;
|
|
154
|
-
lastName
|
|
154
|
+
lastName? /** The primary username that represents the user */: string;
|
|
155
155
|
};
|
|
156
156
|
email?: string;
|
|
157
157
|
} | undefined;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { APIError, BetterAuthError } from "../error/index.mjs";
|
|
1
2
|
import { logger } from "../env/logger.mjs";
|
|
2
|
-
import {
|
|
3
|
+
import { getPrimaryClientId } from "../oauth2/utils.mjs";
|
|
3
4
|
import { createAuthorizationURL } from "../oauth2/create-authorization-url.mjs";
|
|
4
5
|
import { refreshAccessToken } from "../oauth2/refresh-access-token.mjs";
|
|
5
6
|
import { validateAuthorizationCode } from "../oauth2/validate-authorization-code.mjs";
|
|
@@ -16,6 +17,10 @@ const microsoft = (options) => {
|
|
|
16
17
|
id: "microsoft",
|
|
17
18
|
name: "Microsoft EntraID",
|
|
18
19
|
createAuthorizationURL(data) {
|
|
20
|
+
if (!getPrimaryClientId(options.clientId)) {
|
|
21
|
+
logger.error("Client Id is required for Microsoft Entra ID. Make sure to provide it in the options.");
|
|
22
|
+
throw new BetterAuthError("CLIENT_ID_AND_SECRET_REQUIRED");
|
|
23
|
+
}
|
|
19
24
|
const scopes = options.disableDefaultScope ? [] : [
|
|
20
25
|
"openid",
|
|
21
26
|
"profile",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { logger } from "../env/logger.mjs";
|
|
2
1
|
import { BetterAuthError } from "../error/index.mjs";
|
|
2
|
+
import { logger } from "../env/logger.mjs";
|
|
3
3
|
import { createAuthorizationURL } from "../oauth2/create-authorization-url.mjs";
|
|
4
4
|
import { refreshAccessToken } from "../oauth2/refresh-access-token.mjs";
|
|
5
5
|
import { validateAuthorizationCode } from "../oauth2/validate-authorization-code.mjs";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { logger } from "../env/logger.mjs";
|
|
2
1
|
import { BetterAuthError } from "../error/index.mjs";
|
|
2
|
+
import { logger } from "../env/logger.mjs";
|
|
3
3
|
import { createAuthorizationURL } from "../oauth2/create-authorization-url.mjs";
|
|
4
4
|
import { base64 } from "@better-auth/utils/base64";
|
|
5
5
|
import { betterFetch } from "@better-fetch/fetch";
|
package/template/apps/web/node_modules/@better-auth/core/dist/social-providers/salesforce.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { logger } from "../env/logger.mjs";
|
|
2
1
|
import { BetterAuthError } from "../error/index.mjs";
|
|
2
|
+
import { logger } from "../env/logger.mjs";
|
|
3
3
|
import { createAuthorizationURL } from "../oauth2/create-authorization-url.mjs";
|
|
4
4
|
import { refreshAccessToken } from "../oauth2/refresh-access-token.mjs";
|
|
5
5
|
import { validateAuthorizationCode } from "../oauth2/validate-authorization-code.mjs";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { APIError as APIError$1 } from "../error/index.mjs";
|
|
2
|
+
import { APIError } from "better-call";
|
|
3
|
+
//#region src/utils/is-api-error.ts
|
|
4
|
+
function isAPIError(error) {
|
|
5
|
+
return error instanceof APIError || error instanceof APIError$1 || error?.name === "APIError";
|
|
6
|
+
}
|
|
7
|
+
//#endregion
|
|
8
|
+
export { isAPIError };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@better-auth/core",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.7",
|
|
4
4
|
"description": "The most comprehensive authentication framework for TypeScript.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -93,6 +93,12 @@
|
|
|
93
93
|
"./instrumentation": {
|
|
94
94
|
"dev-source": "./src/instrumentation/index.ts",
|
|
95
95
|
"types": "./dist/instrumentation/index.d.mts",
|
|
96
|
+
"node": "./dist/instrumentation/index.mjs",
|
|
97
|
+
"deno": "./dist/instrumentation/index.mjs",
|
|
98
|
+
"bun": "./dist/instrumentation/index.mjs",
|
|
99
|
+
"edge": "./dist/instrumentation/pure.index.mjs",
|
|
100
|
+
"workerd": "./dist/instrumentation/index.mjs",
|
|
101
|
+
"browser": "./dist/instrumentation/pure.index.mjs",
|
|
96
102
|
"default": "./dist/instrumentation/index.mjs"
|
|
97
103
|
}
|
|
98
104
|
},
|
|
@@ -3,9 +3,34 @@ import type {
|
|
|
3
3
|
EndpointOptions,
|
|
4
4
|
StrictEndpoint,
|
|
5
5
|
} from "better-call";
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
createEndpoint,
|
|
8
|
+
createMiddleware,
|
|
9
|
+
kAPIErrorHeaderSymbol,
|
|
10
|
+
} from "better-call";
|
|
7
11
|
import { runWithEndpointContext } from "../context";
|
|
8
12
|
import type { AuthContext } from "../types";
|
|
13
|
+
import { isAPIError } from "../utils/is-api-error";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Better-call's createEndpoint re-throws APIError without exposing the headers
|
|
17
|
+
* accumulated on ctx.responseHeaders (e.g. Set-Cookie from deleteSessionCookie
|
|
18
|
+
* before throw). Attach them to the error via kAPIErrorHeaderSymbol — matching
|
|
19
|
+
* better-call's createMiddleware contract so the outer pipeline can merge them
|
|
20
|
+
* into the response.
|
|
21
|
+
*/
|
|
22
|
+
function attachResponseHeadersToAPIError(
|
|
23
|
+
responseHeaders: Headers | undefined,
|
|
24
|
+
e: unknown,
|
|
25
|
+
): void {
|
|
26
|
+
if (!isAPIError(e) || !responseHeaders) return;
|
|
27
|
+
Object.defineProperty(e, kAPIErrorHeaderSymbol, {
|
|
28
|
+
enumerable: false,
|
|
29
|
+
configurable: true,
|
|
30
|
+
value: responseHeaders,
|
|
31
|
+
writable: false,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
9
34
|
|
|
10
35
|
export const optionsMiddleware = createMiddleware(async () => {
|
|
11
36
|
/**
|
|
@@ -76,6 +101,17 @@ export function createAuthEndpoint<
|
|
|
76
101
|
const handler: EndpointHandler<Path, Opts, R> =
|
|
77
102
|
typeof handlerOrOptions === "function" ? handlerOrOptions : handlerOrNever;
|
|
78
103
|
|
|
104
|
+
// todo: prettify the code, we want to call `runWithEndpointContext` to top level
|
|
105
|
+
const wrapped: EndpointHandler<Path, Opts, R> = async (ctx) => {
|
|
106
|
+
const runtimeCtx = ctx as unknown as { responseHeaders?: Headers };
|
|
107
|
+
try {
|
|
108
|
+
return await runWithEndpointContext(ctx as any, () => handler(ctx));
|
|
109
|
+
} catch (e) {
|
|
110
|
+
attachResponseHeadersToAPIError(runtimeCtx.responseHeaders, e);
|
|
111
|
+
throw e;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
79
115
|
if (path) {
|
|
80
116
|
return createEndpoint(
|
|
81
117
|
path,
|
|
@@ -83,8 +119,7 @@ export function createAuthEndpoint<
|
|
|
83
119
|
...options,
|
|
84
120
|
use: [...(options?.use || []), ...use],
|
|
85
121
|
},
|
|
86
|
-
|
|
87
|
-
async (ctx) => runWithEndpointContext(ctx as any, () => handler(ctx)),
|
|
122
|
+
wrapped,
|
|
88
123
|
);
|
|
89
124
|
}
|
|
90
125
|
|
|
@@ -93,8 +128,7 @@ export function createAuthEndpoint<
|
|
|
93
128
|
...options,
|
|
94
129
|
use: [...(options?.use || []), ...use],
|
|
95
130
|
},
|
|
96
|
-
|
|
97
|
-
async (ctx) => runWithEndpointContext(ctx as any, () => handler(ctx)),
|
|
131
|
+
wrapped,
|
|
98
132
|
);
|
|
99
133
|
}
|
|
100
134
|
|
|
@@ -1,52 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
type OpenTelemetryAPI = Pick<
|
|
4
|
-
typeof import("@opentelemetry/api"),
|
|
5
|
-
"trace" | "SpanStatusCode"
|
|
6
|
-
>;
|
|
7
|
-
|
|
8
|
-
function createNoopSpan(): Span {
|
|
9
|
-
return {
|
|
10
|
-
end(): void {},
|
|
11
|
-
setAttribute(_key: string, _value: unknown): void {},
|
|
12
|
-
setStatus(_status: unknown): void {},
|
|
13
|
-
recordException(_exception: unknown): void {},
|
|
14
|
-
} as Span;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function createNoopTracer(noopSpanInstance: Span): Tracer {
|
|
18
|
-
function startActiveSpan<F extends (span: Span) => unknown>(
|
|
19
|
-
_name: string,
|
|
20
|
-
_options: { attributes?: Record<string, string | number | boolean> },
|
|
21
|
-
fn: F,
|
|
22
|
-
): ReturnType<F> {
|
|
23
|
-
return fn(noopSpanInstance) as ReturnType<F>;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return { startActiveSpan } as Tracer;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function createNoopTraceAPI() {
|
|
30
|
-
const noopTracer = createNoopTracer(createNoopSpan());
|
|
31
|
-
return {
|
|
32
|
-
getTracer(_name?: string, _version?: string) {
|
|
33
|
-
return noopTracer;
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function createNoopOpenTelemetryAPI(): OpenTelemetryAPI {
|
|
39
|
-
return {
|
|
40
|
-
SpanStatusCode: {
|
|
41
|
-
UNSET: 0,
|
|
42
|
-
OK: 1,
|
|
43
|
-
ERROR: 2,
|
|
44
|
-
},
|
|
45
|
-
trace: createNoopTraceAPI(),
|
|
46
|
-
} as OpenTelemetryAPI;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const noopOpenTelemetryAPI = createNoopOpenTelemetryAPI();
|
|
1
|
+
import type { OpenTelemetryAPI } from "./noop";
|
|
2
|
+
import { noopOpenTelemetryAPI } from "./noop";
|
|
50
3
|
|
|
51
4
|
let openTelemetryAPIPromise: Promise<void> | undefined;
|
|
52
5
|
let openTelemetryAPI: OpenTelemetryAPI | undefined;
|