Skip to content

Commit

Permalink
normalize AuthError message
Browse files Browse the repository at this point in the history
  • Loading branch information
k-taro56 committed May 19, 2024
1 parent 4fc8fe8 commit db9dc91
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
20 changes: 10 additions & 10 deletions packages/core/src/lib/actions/callback/oauth/checks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const pkce = {
const codeVerifier = cookies?.[options.cookies.pkceCodeVerifier.name]

if (!codeVerifier)
throw new InvalidCheck("PKCE code_verifier cookie was missing.")
throw new InvalidCheck("PKCE code_verifier cookie was missing")

const value = await decode<CheckPayload>({
...options.jwt,
Expand All @@ -83,7 +83,7 @@ export const pkce = {
})

if (!value?.value)
throw new InvalidCheck("PKCE code_verifier value could not be parsed.")
throw new InvalidCheck("PKCE code_verifier value could not be parsed")

// Clear the pkce code verifier cookie after use
resCookies.push({
Expand Down Expand Up @@ -117,7 +117,7 @@ export const state = {
if (!provider.checks.includes("state")) {
if (data) {
throw new InvalidCheck(
"State data was provided but the provider is not configured to use state."
"State data was provided but the provider is not configured to use state"
)
}
return
Expand Down Expand Up @@ -155,7 +155,7 @@ export const state = {

const state = cookies?.[options.cookies.state.name]

if (!state) throw new InvalidCheck("State cookie was missing.")
if (!state) throw new InvalidCheck("State cookie was missing")

// IDEA: Let the user do something with the returned state
const encodedState = await decode<CheckPayload>({
Expand All @@ -165,12 +165,12 @@ export const state = {
})

if (!encodedState?.value)
throw new InvalidCheck("State (cookie) value could not be parsed.")
throw new InvalidCheck("State (cookie) value could not be parsed")

const decodedState = decodeState(encodedState.value)

if (!decodedState)
throw new InvalidCheck("State (encoded) value could not be parsed.")
throw new InvalidCheck("State (encoded) value could not be parsed")

if (decodedState.random !== paramRandom)
throw new InvalidCheck(
Expand Down Expand Up @@ -214,7 +214,7 @@ export const nonce = {
if (!provider?.checks?.includes("nonce")) return

const nonce = cookies?.[options.cookies.nonce.name]
if (!nonce) throw new InvalidCheck("Nonce cookie was missing.")
if (!nonce) throw new InvalidCheck("Nonce cookie was missing")

const value = await decode<CheckPayload>({
...options.jwt,
Expand All @@ -223,7 +223,7 @@ export const nonce = {
})

if (!value?.value)
throw new InvalidCheck("Nonce value could not be parsed.")
throw new InvalidCheck("Nonce value could not be parsed")

// Clear the nonce cookie after use
resCookies.push({
Expand Down Expand Up @@ -294,7 +294,7 @@ export const webauthnChallenge = {
): Promise<WebAuthnChallengeCookie> {
const challenge = cookies?.[options.cookies.webauthnChallenge.name]

if (!challenge) throw new InvalidCheck("Challenge cookie missing.")
if (!challenge) throw new InvalidCheck("Challenge cookie missing")

const value = await decode<CheckPayload>({
...options.jwt,
Expand All @@ -303,7 +303,7 @@ export const webauthnChallenge = {
})

if (!value?.value)
throw new InvalidCheck("Challenge value could not be parsed.")
throw new InvalidCheck("Challenge value could not be parsed")

// Clear the pkce code verifier cookie after use
const cookie = {
Expand Down
16 changes: 8 additions & 8 deletions packages/core/src/lib/utils/assert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export function assertConfig(
}

if (!options.secret?.length) {
return new MissingSecret("Please define a `secret`.")
return new MissingSecret("Please define a `secret`")
}

const callbackUrlParam = request.query?.callbackUrl as string | undefined
Expand Down Expand Up @@ -141,7 +141,7 @@ export function assertConfig(

if (key) {
return new InvalidEndpoints(
`Provider "${provider.id}" is missing both \`issuer\` and \`${key}\` endpoint config. At least one of them is required.`
`Provider "${provider.id}" is missing both \`issuer\` and \`${key}\` endpoint config. At least one of them is required`
)
}
}
Expand All @@ -165,7 +165,7 @@ export function assertConfig(
// Make sure only one webauthn provider has "enableConditionalUI" set to true
if (hasConditionalUIProvider) {
return new DuplicateConditionalUI(
`Multiple webauthn providers have 'enableConditionalUI' set to True. Only one provider can have this option enabled at a time.`
`Multiple webauthn providers have 'enableConditionalUI' set to True. Only one provider can have this option enabled at a time`
)
}
hasConditionalUIProvider = true
Expand All @@ -177,7 +177,7 @@ export function assertConfig(
)
if (!hasWebauthnFormField) {
return new MissingWebAuthnAutocomplete(
`Provider "${provider.id}" has 'enableConditionalUI' set to True, but none of its formFields have 'webauthn' in their autocomplete param.`
`Provider "${provider.id}" has 'enableConditionalUI' set to True, but none of its formFields have 'webauthn' in their autocomplete param`
)
}
}
Expand Down Expand Up @@ -217,11 +217,11 @@ export function assertConfig(
) {
if (hasEmail) {
if (!adapter)
return new MissingAdapter("Email login requires an adapter.")
return new MissingAdapter("Email login requires an adapter")
requiredMethods.push(...emailMethods)
} else {
if (!adapter)
return new MissingAdapter("Database session requires an adapter.")
return new MissingAdapter("Database session requires an adapter")
requiredMethods.push(...sessionMethods)
}
}
Expand All @@ -232,11 +232,11 @@ export function assertConfig(
warnings.push("experimental-webauthn")
} else {
return new ExperimentalFeatureNotEnabled(
"WebAuthn is an experimental feature. To enable it, set `experimental.enableWebAuthn` to `true` in your config."
"WebAuthn is an experimental feature. To enable it, set `experimental.enableWebAuthn` to `true` in your config"
)
}

if (!adapter) return new MissingAdapter("WebAuthn requires an adapter.")
if (!adapter) return new MissingAdapter("WebAuthn requires an adapter")
requiredMethods.push(...webauthnMethods)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/lib/utils/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export async function toInternalRequest(
): Promise<RequestInternal | undefined> {
try {
if (req.method !== "GET" && req.method !== "POST")
throw new UnknownAction("Only GET and POST requests are supported.")
throw new UnknownAction("Only GET and POST requests are supported")

// Defaults are usually set in the `init` function, but this is needed below
config.basePath ??= "/auth"
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/lib/utils/webauthn-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ export async function verifyAuthenticate(
// Make sure the response was verified
if (!verified) {
throw new WebAuthnVerificationError(
"WebAuthn authentication response could not be verified."
"WebAuthn authentication response could not be verified"
)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/providers/webauthn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ const getUserInfo: GetUserInfo = async (options, request) => {
const { adapter } = options
if (!adapter)
throw new MissingAdapter(
"WebAuthn provider requires a database adapter to be configured."
"WebAuthn provider requires a database adapter to be configured"
)

// Get email address from the query.
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/assert-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe("Assert user config correctness", () => {
"There was a problem with the server configuration. Check the server logs for more information.",
})
expect(logger?.error).toHaveBeenCalledWith(
new MissingSecret("Please define a `secret`.")
new MissingSecret("Please define a `secret`")
)
})

Expand Down

0 comments on commit db9dc91

Please sign in to comment.