Socket
Socket
Sign inDemoInstall

@auth/core

Package Overview
Dependencies
Maintainers
2
Versions
97
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@auth/core - npm Package Compare versions

Comparing version 0.24.0 to 0.25.0

lib/utils/env.d.ts

3

index.d.ts

@@ -39,2 +39,3 @@ /**

import { raw, skipCSRFCheck } from "./lib/index.js";
import { setEnvDefaults, createActionURL } from "./lib/utils/env.js";
import { type LoggerInstance } from "./lib/utils/logger.js";

@@ -45,3 +46,3 @@ import type { Adapter } from "./adapters.js";

import { JWTOptions } from "./jwt.js";
export { skipCSRFCheck, raw };
export { skipCSRFCheck, raw, setEnvDefaults, createActionURL };
export declare function Auth(request: Request, config: AuthConfig): Promise<ResponseInternal>;

@@ -48,0 +49,0 @@ export declare function Auth(request: Request, config: Omit<AuthConfig, "raw">): Promise<Response>;

@@ -41,6 +41,7 @@ /**

import { AuthInternal, raw, skipCSRFCheck } from "./lib/index.js";
import { setEnvDefaults, createActionURL } from "./lib/utils/env.js";
import renderPage from "./lib/pages/index.js";
import { logger, setLogger } from "./lib/utils/logger.js";
import { toInternalRequest, toResponse } from "./lib/utils/web.js";
export { skipCSRFCheck, raw };
export { skipCSRFCheck, raw, setEnvDefaults, createActionURL };
/**

@@ -81,6 +82,5 @@ * Core functionality provided by Auth.js.

internalRequest.method !== "GET") {
return new Response(JSON.stringify({
return Response.json({
message: "There was a problem with the server configuration. Check the server logs for more information.",
code: assertionResult.name,
}), { status: 500, headers: { "Content-Type": "application/json" } });
}, { status: 500 });
}

@@ -87,0 +87,0 @@ const { pages, theme } = config;

@@ -47,7 +47,9 @@ // TODO: Make this file smaller

}
await handleAuthorized({
const redirect = await handleAuthorized({
user: userByAccount ?? userFromProvider,
account,
profile: OAuthProfile,
}, options.callbacks.signIn);
}, options);
if (redirect)
return { redirect, cookies };
const { user, session, isNewUser } = await handleLoginOrRegister(sessionStore.value, userFromProvider, account, options);

@@ -144,3 +146,5 @@ if (useJwtSession) {

};
await handleAuthorized({ user, account }, options.callbacks.signIn);
const redirect = await handleAuthorized({ user, account }, options);
if (redirect)
return { redirect, cookies };
// Sign user in

@@ -221,3 +225,5 @@ const { user: loggedInUser, session, isNewUser, } = await handleLoginOrRegister(sessionStore.value, user, account, options);

};
await handleAuthorized({ user, account, credentials }, options.callbacks.signIn);
const redirect = await handleAuthorized({ user, account, credentials }, options);
if (redirect)
return { redirect, cookies };
const defaultToken = {

@@ -265,7 +271,7 @@ name: user.name,

}
async function handleAuthorized(params, signIn) {
async function handleAuthorized(params, config) {
let authorized;
const { signIn, redirect } = config.callbacks;
try {
const authorized = await signIn(params);
if (!authorized)
throw new AuthorizedCallbackError("AccessDenied");
authorized = await signIn(params);
}

@@ -277,2 +283,7 @@ catch (e) {

}
if (!authorized)
throw new AuthorizedCallbackError("AccessDenied");
if (typeof authorized !== "string")
return;
return await redirect({ url: authorized, baseUrl: config.url.origin });
}
import { getAuthorizationUrl } from "./authorization-url.js";
import { sendToken } from "./send-token.js";
export async function signIn(request, cookies, options) {
const signInUrl = `${options.url}/signin`;
const signInUrl = `${options.url.origin}${options.basePath}/signin`;
if (!options.provider)

@@ -16,3 +16,4 @@ return { redirect: signInUrl, cookies };

case "email": {
return await sendToken(request, options);
const response = await sendToken(request, options);
return { ...response, cookies };
}

@@ -19,0 +20,0 @@ default:

@@ -10,3 +10,3 @@ import { createHash, randomString, toRequest } from "../../utils/web.js";

const { body } = request;
const { provider, url, callbacks, adapter } = options;
const { provider, callbacks, adapter } = options;
const normalizer = provider.normalizeIdentifier ?? defaultNormalizer;

@@ -35,2 +35,10 @@ const email = normalizer(body?.email);

throw new AuthorizedCallbackError("AccessDenied");
if (typeof authorized === "string") {
return {
redirect: await callbacks.redirect({
url: authorized,
baseUrl: options.url.origin,
}),
};
}
const { callbackUrl, theme } = options;

@@ -37,0 +45,0 @@ const token = (await provider.generateVerificationToken?.()) ?? randomString(32);

{
"name": "@auth/core",
"version": "0.24.0",
"version": "0.25.0",
"description": "Authentication for the Web.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -61,3 +61,8 @@ /**

type: "oauth",
authorization: "https://www.facebook.com/v15.0/dialog/oauth?scope=email",
authorization: {
url: "https://www.facebook.com/v15.0/dialog/oauth",
params: {
scope: 'email',
},
},
token: "https://graph.facebook.com/oauth/access_token",

@@ -64,0 +69,0 @@ userinfo: {

@@ -42,2 +42,3 @@ /**

import { AuthInternal, raw, skipCSRFCheck } from "./lib/index.js"
import { setEnvDefaults, createActionURL } from "./lib/utils/env.js"
import renderPage from "./lib/pages/index.js"

@@ -59,3 +60,3 @@ import { logger, setLogger, type LoggerInstance } from "./lib/utils/logger.js"

export { skipCSRFCheck, raw }
export { skipCSRFCheck, raw, setEnvDefaults, createActionURL }

@@ -118,9 +119,8 @@ export async function Auth(

) {
return new Response(
JSON.stringify({
return Response.json(
{
message:
"There was a problem with the server configuration. Check the server logs for more information.",
code: assertionResult.name,
}),
{ status: 500, headers: { "Content-Type": "application/json" } }
},
{ status: 500 }
)

@@ -127,0 +127,0 @@ }

@@ -104,3 +104,3 @@ // TODO: Make this file smaller

await handleAuthorized(
const redirect = await handleAuthorized(
{

@@ -111,4 +111,5 @@ user: userByAccount ?? userFromProvider,

},
options.callbacks.signIn
options
)
if (redirect) return { redirect, cookies }

@@ -225,3 +226,4 @@ const { user, session, isNewUser } = await handleLoginOrRegister(

await handleAuthorized({ user, account }, options.callbacks.signIn)
const redirect = await handleAuthorized({ user, account }, options)
if (redirect) return { redirect, cookies }

@@ -325,6 +327,7 @@ // Sign user in

await handleAuthorized(
const redirect = await handleAuthorized(
{ user, account, credentials },
options.callbacks.signIn
options
)
if (redirect) return { redirect, cookies }

@@ -383,7 +386,8 @@ const defaultToken = {

params: Parameters<InternalOptions["callbacks"]["signIn"]>[0],
signIn: InternalOptions["callbacks"]["signIn"]
) {
config: InternalOptions
): Promise<string | undefined> {
let authorized
const { signIn, redirect } = config.callbacks
try {
const authorized = await signIn(params)
if (!authorized) throw new AuthorizedCallbackError("AccessDenied")
authorized = await signIn(params)
} catch (e) {

@@ -393,2 +397,5 @@ if (e instanceof AuthError) throw e

}
if (!authorized) throw new AuthorizedCallbackError("AccessDenied")
if (typeof authorized !== "string") return
return await redirect({ url: authorized, baseUrl: config.url.origin })
}

@@ -16,3 +16,3 @@ import { getAuthorizationUrl } from "./authorization-url.js"

): Promise<ResponseInternal> {
const signInUrl = `${options.url}/signin`
const signInUrl = `${options.url.origin}${options.basePath}/signin`

@@ -32,3 +32,4 @@ if (!options.provider) return { redirect: signInUrl, cookies }

case "email": {
return await sendToken(request, options)
const response = await sendToken(request, options)
return { ...response, cookies }
}

@@ -35,0 +36,0 @@ default:

@@ -17,3 +17,3 @@ import { createHash, randomString, toRequest } from "../../utils/web.js"

const { body } = request
const { provider, url, callbacks, adapter } = options
const { provider, callbacks, adapter } = options
const normalizer = provider.normalizeIdentifier ?? defaultNormalizer

@@ -43,2 +43,10 @@ const email = normalizer(body?.email)

if (!authorized) throw new AuthorizedCallbackError("AccessDenied")
if (typeof authorized === "string") {
return {
redirect: await callbacks.redirect({
url: authorized,
baseUrl: options.url.origin,
}),
}
}

@@ -45,0 +53,0 @@ const { callbackUrl, theme } = options

@@ -87,3 +87,8 @@ /**

type: "oauth",
authorization: "https://www.facebook.com/v15.0/dialog/oauth?scope=email",
authorization: {
url: "https://www.facebook.com/v15.0/dialog/oauth",
params: {
scope: 'email',
},
},
token: "https://graph.facebook.com/oauth/access_token",

@@ -90,0 +95,0 @@ userinfo: {

@@ -187,4 +187,5 @@ /**

* Controls whether a user is allowed to sign in or not.
* Returning `true` continues the sign-in flow, while
* returning `false` throws an `AuthorizedCallbackError` with the message `"AccessDenied"`.
* Returning `true` continues the sign-in flow.
* Returning `false` or throwing an error will stop the sign-in flow and redirect the user to the error page.
* Returning a string will redirect the user to the specified URL.
*

@@ -225,3 +226,3 @@ * Unhandled errors will throw an `AuthorizedCallbackError` with the message set to the original error.

credentials?: Record<string, CredentialInput>
}) => Awaitable<boolean>
}) => Awaitable<boolean | string>
/**

@@ -228,0 +229,0 @@ * This callback is called anytime the user is redirected to a callback URL (e.g. on signin or signout).

@@ -165,4 +165,5 @@ /**

* Controls whether a user is allowed to sign in or not.
* Returning `true` continues the sign-in flow, while
* returning `false` throws an `AuthorizedCallbackError` with the message `"AccessDenied"`.
* Returning `true` continues the sign-in flow.
* Returning `false` or throwing an error will stop the sign-in flow and redirect the user to the error page.
* Returning a string will redirect the user to the specified URL.
*

@@ -203,3 +204,3 @@ * Unhandled errors will throw an `AuthorizedCallbackError` with the message set to the original error.

credentials?: Record<string, CredentialInput>;
}) => Awaitable<boolean>;
}) => Awaitable<boolean | string>;
/**

@@ -206,0 +207,0 @@ * This callback is called anytime the user is redirected to a callback URL (e.g. on signin or signout).

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc