@auth/sveltekit
Advanced tools
Comparing version 0.2.2 to 0.3.0
@@ -30,2 +30,19 @@ /** | ||
* | ||
* or to use sveltekit platform environment variables for platforms like Cloudflare | ||
* | ||
* ```ts title="src/hooks.server.ts" | ||
* import { SvelteKitAuth } from "@auth/sveltekit" | ||
* import GitHub from "@auth/core/providers/github" | ||
* import type { Handle } from "@sveltejs/kit"; | ||
* | ||
* export const handle = SvelteKitAuth(async (event) => { | ||
* const authOptions = { | ||
* providers: [GitHub({ clientId: event.platform.env.GITHUB_ID, clientSecret: event.platform.env.GITHUB_SECRET })] | ||
* secret: event.platform.env.AUTH_SECRET, | ||
* trustHost: true | ||
* } | ||
* return authOptions | ||
* }) satisfies Handle; | ||
* ``` | ||
* | ||
* Don't forget to set the `AUTH_SECRET` [environment variable](https://kit.svelte.dev/docs/modules#$env-dynamic-private). This should be a minimum of 32 characters, random string. On UNIX systems you can use `openssl rand -hex 32` or check out `https://generate-secret.vercel.app/32`. | ||
@@ -75,3 +92,3 @@ * | ||
* The above example checks for a session available in `$page.data.session`, however that needs to be set by us somewhere. | ||
* If you want this data to be available to all your routes you can add this to your root `+layout.server.ts` file. | ||
* If you want this data to be available to all your routes you can add this to `src/routes/+layout.server.ts`. | ||
* The following code sets the session data in the `$page` store to be available to all routes. | ||
@@ -190,3 +207,3 @@ * | ||
*/ | ||
import type { Handle } from "@sveltejs/kit"; | ||
import type { Handle, RequestEvent } from "@sveltejs/kit"; | ||
import type { AuthConfig, Session } from "@auth/core/types"; | ||
@@ -205,2 +222,3 @@ export declare function getSession(req: Request, config: AuthConfig): ReturnType<App.Locals["getSession"]>; | ||
} | ||
type DynamicSvelteKitAuthConfig = (event: RequestEvent) => PromiseLike<SvelteKitAuthConfig>; | ||
/** | ||
@@ -210,3 +228,3 @@ * The main entry point to `@auth/sveltekit` | ||
*/ | ||
export declare function SvelteKitAuth(options: SvelteKitAuthConfig): Handle; | ||
export declare function SvelteKitAuth(options: SvelteKitAuthConfig | DynamicSvelteKitAuthConfig): Handle; | ||
declare global { | ||
@@ -227,1 +245,2 @@ namespace App { | ||
} | ||
export {}; |
36
index.js
@@ -30,2 +30,19 @@ /** | ||
* | ||
* or to use sveltekit platform environment variables for platforms like Cloudflare | ||
* | ||
* ```ts title="src/hooks.server.ts" | ||
* import { SvelteKitAuth } from "@auth/sveltekit" | ||
* import GitHub from "@auth/core/providers/github" | ||
* import type { Handle } from "@sveltejs/kit"; | ||
* | ||
* export const handle = SvelteKitAuth(async (event) => { | ||
* const authOptions = { | ||
* providers: [GitHub({ clientId: event.platform.env.GITHUB_ID, clientSecret: event.platform.env.GITHUB_SECRET })] | ||
* secret: event.platform.env.AUTH_SECRET, | ||
* trustHost: true | ||
* } | ||
* return authOptions | ||
* }) satisfies Handle; | ||
* ``` | ||
* | ||
* Don't forget to set the `AUTH_SECRET` [environment variable](https://kit.svelte.dev/docs/modules#$env-dynamic-private). This should be a minimum of 32 characters, random string. On UNIX systems you can use `openssl rand -hex 32` or check out `https://generate-secret.vercel.app/32`. | ||
@@ -75,3 +92,3 @@ * | ||
* The above example checks for a session available in `$page.data.session`, however that needs to be set by us somewhere. | ||
* If you want this data to be available to all your routes you can add this to your root `+layout.server.ts` file. | ||
* If you want this data to be available to all your routes you can add this to `src/routes/+layout.server.ts`. | ||
* The following code sets the session data in the `$page` store to be available to all routes. | ||
@@ -217,4 +234,8 @@ * | ||
]; | ||
function AuthHandle(prefix, authOptions) { | ||
return function ({ event, resolve }) { | ||
function AuthHandle(svelteKitAuthOptions) { | ||
return async function ({ event, resolve }) { | ||
const authOptions = typeof svelteKitAuthOptions === "object" | ||
? svelteKitAuthOptions | ||
: await svelteKitAuthOptions(event); | ||
const { prefix = "/auth" } = authOptions; | ||
const { url, request } = event; | ||
@@ -236,6 +257,7 @@ event.locals.getSession ??= () => getSession(request, authOptions); | ||
export function SvelteKitAuth(options) { | ||
const { prefix = "/auth", ...authOptions } = options; | ||
authOptions.secret ??= env.AUTH_SECRET; | ||
authOptions.trustHost ??= !!(env.AUTH_TRUST_HOST ?? env.VERCEL ?? dev); | ||
return AuthHandle(prefix, authOptions); | ||
if (typeof options === "object") { | ||
options.secret ??= env.AUTH_SECRET; | ||
options.trustHost ??= !!(env.AUTH_TRUST_HOST ?? env.VERCEL ?? dev); | ||
} | ||
return AuthHandle(options); | ||
} |
{ | ||
"name": "@auth/sveltekit", | ||
"version": "0.2.2", | ||
"version": "0.3.0", | ||
"description": "Authentication for SvelteKit.", | ||
@@ -39,3 +39,3 @@ "keywords": [ | ||
"dependencies": { | ||
"@auth/core": "0.4.0" | ||
"@auth/core": "0.5.1" | ||
}, | ||
@@ -42,0 +42,0 @@ "peerDependencies": { |
@@ -29,3 +29,20 @@ /** | ||
* ``` | ||
* | ||
* or to use sveltekit platform environment variables for platforms like Cloudflare | ||
* | ||
* ```ts title="src/hooks.server.ts" | ||
* import { SvelteKitAuth } from "@auth/sveltekit" | ||
* import GitHub from "@auth/core/providers/github" | ||
* import type { Handle } from "@sveltejs/kit"; | ||
* | ||
* export const handle = SvelteKitAuth(async (event) => { | ||
* const authOptions = { | ||
* providers: [GitHub({ clientId: event.platform.env.GITHUB_ID, clientSecret: event.platform.env.GITHUB_SECRET })] | ||
* secret: event.platform.env.AUTH_SECRET, | ||
* trustHost: true | ||
* } | ||
* return authOptions | ||
* }) satisfies Handle; | ||
* ``` | ||
* | ||
* Don't forget to set the `AUTH_SECRET` [environment variable](https://kit.svelte.dev/docs/modules#$env-dynamic-private). This should be a minimum of 32 characters, random string. On UNIX systems you can use `openssl rand -hex 32` or check out `https://generate-secret.vercel.app/32`. | ||
@@ -75,3 +92,3 @@ * | ||
* The above example checks for a session available in `$page.data.session`, however that needs to be set by us somewhere. | ||
* If you want this data to be available to all your routes you can add this to your root `+layout.server.ts` file. | ||
* If you want this data to be available to all your routes you can add this to `src/routes/+layout.server.ts`. | ||
* The following code sets the session data in the `$page` store to be available to all routes. | ||
@@ -192,3 +209,3 @@ * | ||
/// <reference types="@sveltejs/kit" /> | ||
import type { Handle } from "@sveltejs/kit" | ||
import type { Handle, RequestEvent } from "@sveltejs/kit" | ||
@@ -243,4 +260,11 @@ import { dev } from "$app/environment" | ||
function AuthHandle(prefix: string, authOptions: AuthConfig): Handle { | ||
return function ({ event, resolve }) { | ||
type DynamicSvelteKitAuthConfig = (event: RequestEvent) => PromiseLike<SvelteKitAuthConfig> | ||
function AuthHandle(svelteKitAuthOptions: SvelteKitAuthConfig | DynamicSvelteKitAuthConfig): Handle { | ||
return async function ({ event, resolve }) { | ||
const authOptions = | ||
typeof svelteKitAuthOptions === "object" | ||
? svelteKitAuthOptions | ||
: await svelteKitAuthOptions(event) | ||
const { prefix = "/auth" } = authOptions | ||
const { url, request } = event | ||
@@ -266,7 +290,8 @@ | ||
*/ | ||
export function SvelteKitAuth(options: SvelteKitAuthConfig): Handle { | ||
const { prefix = "/auth", ...authOptions } = options | ||
authOptions.secret ??= env.AUTH_SECRET | ||
authOptions.trustHost ??= !!(env.AUTH_TRUST_HOST ?? env.VERCEL ?? dev) | ||
return AuthHandle(prefix, authOptions) | ||
export function SvelteKitAuth(options: SvelteKitAuthConfig | DynamicSvelteKitAuthConfig): Handle { | ||
if (typeof options === "object") { | ||
options.secret ??= env.AUTH_SECRET | ||
options.trustHost ??= !!(env.AUTH_TRUST_HOST ?? env.VERCEL ?? dev) | ||
} | ||
return AuthHandle(options) | ||
} | ||
@@ -273,0 +298,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
42979
979
+ Added@auth/core@0.5.1(transitive)
- Removed@auth/core@0.4.0(transitive)
Updated@auth/core@0.5.1