-
Notifications
You must be signed in to change notification settings - Fork 1
refactor(core): improve user messages with clearer context #189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,5 @@ | ||||||||||||||||||||||||||||||||||
| import { AuthInternalError } from "@/shared/errors.ts" | ||||||||||||||||||||||||||||||||||
| import { OAuthAuthorization } from "@/schemas.ts" | ||||||||||||||||||||||||||||||||||
| import { AuraAuthError } from "@/shared/unstable_error.ts" | ||||||||||||||||||||||||||||||||||
| import { createPKCE, createSecretValue } from "@/shared/crypto.ts" | ||||||||||||||||||||||||||||||||||
| import type { OAuthProvider } from "@/@types/index.ts" | ||||||||||||||||||||||||||||||||||
| import type { GlobalContext } from "@aura-stack/router" | ||||||||||||||||||||||||||||||||||
|
|
@@ -22,7 +22,7 @@ export const buildAuthorizationURL = ( | |||||||||||||||||||||||||||||||||
| const authorizeConfig = oauth.authorize | ||||||||||||||||||||||||||||||||||
| const baseURL = typeof authorizeConfig === "string" ? authorizeConfig : (authorizeConfig?.url ?? oauth.authorizeURL) | ||||||||||||||||||||||||||||||||||
| if (!baseURL) { | ||||||||||||||||||||||||||||||||||
| throw new AuthInternalError("INVALID_OAUTH_CONFIGURATION", "Missing authorization URL in OAuth provider configuration.") | ||||||||||||||||||||||||||||||||||
| throw new AuraAuthError({ code: "INVALID_OAUTH_PROVIDER_URL_CONFIG" }) | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| const url = new URL(baseURL) | ||||||||||||||||||||||||||||||||||
|
Comment on lines
23
to
27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrap The truthiness check only catches missing values. A malformed configured URL still throws a native Suggested fix export const buildAuthorizationURL = (
oauth: OAuthProvider,
redirect_uri: string,
state: string,
code_challenge: string,
code_challenge_method: string
): string => {
const authorizeConfig = oauth.authorize
const baseURL = typeof authorizeConfig === "string" ? authorizeConfig : (authorizeConfig?.url ?? oauth.authorizeURL)
if (!baseURL) {
throw new AuraAuthError({ code: "INVALID_OAUTH_PROVIDER_URL_CONFIG" })
}
- const url = new URL(baseURL)
+ let url: URL
+ try {
+ url = new URL(baseURL)
+ } catch (cause) {
+ throw new AuraAuthError({ code: "INVALID_OAUTH_PROVIDER_URL_CONFIG", cause })
+ }
const authorizeParams = typeof authorizeConfig === "string" ? undefined : authorizeConfig?.params📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||
| const authorizeParams = typeof authorizeConfig === "string" ? undefined : authorizeConfig?.params | ||||||||||||||||||||||||||||||||||
|
|
@@ -69,7 +69,7 @@ export const createAuthorizationURL = async (oauth: OAuthProvider, redirectURI: | |||||||||||||||||||||||||||||||||
| code_challenge_method: method, | ||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||
| throw new AuthInternalError("INVALID_OAUTH_CONFIGURATION", "The OAuth provider configuration is invalid.") | ||||||||||||||||||||||||||||||||||
| throw new AuraAuthError({ code: "INVALID_OAUTH_PROVIDER_SCHEMA_CONFIG" }) | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,7 @@ import type { SignUpConfig } from "@/@types/config.ts" | |
| const signUpConfig = (config: SignUpConfig<any, any>) => { | ||
| return createEndpointConfig({ | ||
| schemas: { | ||
| body: config?.schema ?? z.object({}), | ||
| body: config?.schema ?? z.object(), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🌐 Web query:
💡 Result: In Zod v4, passing an empty object shape—specifically Citations:
Use Suggested fix- body: config?.schema ?? z.object(),
+ body: config?.schema ?? z.object({}),🤖 Prompt for AI Agents |
||
| searchParams: RedirectOptionsSchema, | ||
| }, | ||
| }) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| import { cacheControl, secureApiHeaders } from "@/shared/headers.ts" | ||
| import { HeadersBuilder } from "@aura-stack/router" | ||
| import { AuthInternalError, isAuthErrorWithCode } from "@/shared/errors.ts" | ||
| import { AuraAuthError, isAuraAuthError } from "@/shared/unstable_error.ts" | ||
| import { createAuthorizationURL } from "@/actions/signIn/authorization-url.ts" | ||
| import { createRedirectTo, createRedirectURI, createSignInURL, getBaseURL } from "@/actions/signIn/authorization.ts" | ||
| import type { BuiltInOAuthProvider, FunctionAPIContext, LiteralUnion, SignInAPIOptions, SignInAPIReturn } from "@/@types/index.ts" | ||
|
|
@@ -16,7 +16,7 @@ export const signIn = async ( | |
| const headers = new Headers(headersInit) | ||
| const provider = ctx.oauth[oauth] | ||
| if (!provider) { | ||
| throw new AuthInternalError("INVALID_OAUTH_CONFIGURATION", `The OAuth provider "${oauth}" is not configured.`) | ||
| throw new AuraAuthError({ code: "UNSUPPORTED_OAUTH_CONFIGURATION" }) | ||
| } | ||
|
|
||
| let request = requestInit | ||
|
|
@@ -74,7 +74,7 @@ export const signIn = async ( | |
| } catch (error) { | ||
| let code = "AUTH_SIGN_IN_FAILED" | ||
| let message = "An error occurred during the sign-in process." | ||
| if (isAuthErrorWithCode(error)) { | ||
| if (isAuraAuthError(error)) { | ||
| code = error.code | ||
| message = error.message | ||
| } | ||
|
Comment on lines
+77
to
80
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use
🤖 Prompt for AI Agents |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Malformed JSON is currently reported as an "unknown" OAuth failure in both callback fetchers.
Both implementations call
response.json()inside the same broadtrythat also handles transport failures. If the provider returns a non-JSON or truncated body, the resulting parse error falls into the generic catch and gets reclassified asUNKNOWN_OAUTH_ACCESS_TOKEN_ERROR/UNKNOWN_OAUTH_USER_INFO_ERRORinstead of the existing*_RES_FORMATcodes.packages/core/src/actions/callback/access-token.ts#L70-L94: catch JSON parse failures separately and map them toINVALID_OAUTH_ACCESS_TOKEN_RES_FORMAT.packages/core/src/actions/callback/userinfo.ts#L64-L84: catch JSON parse failures separately and map them toINVALID_OAUTH_USER_INFO_RES_FORMAT.🤖 Prompt for AI Agents