Compare commits

..

13 Commits

Author SHA1 Message Date
Balázs Orbán
7d7d1b2f80 chore(release): bump package version(s) [skip ci] 2022-12-14 13:27:31 +01:00
Balázs Orbán
9a4f3db7b0 chore: format 2022-12-14 13:10:13 +01:00
Balázs Orbán
6aad07a95c chore: update lock file 2022-12-14 13:10:13 +01:00
Balázs Orbán
cfed5b976f fix(sveltekit): include module augmentation 2022-12-14 13:10:13 +01:00
Balázs Orbán
d34108091f fix(core): use preact as JSX runtime 2022-12-14 13:10:13 +01:00
Balázs Orbán
7bf79b89a8 chore(sveltekit): clean up playground 2022-12-14 13:10:13 +01:00
Balázs Orbán
4cd688703a fix(core): drop "in production" from missing secret error 2022-12-14 13:10:13 +01:00
Balázs Orbán
57b176840e chore(release): bump package version(s) [skip ci] 2022-12-14 09:49:43 +01:00
Thang Vu
6298d955df fix(frameworks): run check before building for @auth/sveltekit (#6044)
* fix(frameworks): run check before building for @auth/sveltekit

* run format
2022-12-14 15:44:08 +07:00
Balázs Orbán
2ad1cb3f8c chore(release): bump package version(s) [skip ci] 2022-12-14 02:51:15 +01:00
Balázs Orbán
98707282eb fix(release): tweak package metadata 2022-12-14 02:45:57 +01:00
Balázs Orbán
f4a2430891 fix(release): build packages before publish 2022-12-14 02:45:18 +01:00
Balázs Orbán
575bcb5710 chore: format sveltekit playground 2022-12-13 23:45:32 +01:00
26 changed files with 501 additions and 438 deletions

View File

@@ -1,4 +1,5 @@
GITHUB_CLIENT_ID=
GITHUB_CLIENT_SECRET=
NEXTAUTH_SECRET=
PUBLIC_NEXTAUTH_URL=http://localhost:5173
GITHUB_ID=
GITHUB_SECRET=
# On UNIX systems you can use `openssl rand -hex 32` or
# https://generate-secret.vercel.app/32 to generate a secret.
AUTH_SECRET=

View File

@@ -1,9 +1,6 @@
{
"useTabs": true,
"singleQuote": true,
"trailingComma": "none",
"printWidth": 100,
"plugins": ["prettier-plugin-svelte"],
"pluginSearchDirs": ["."],
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
"semi": false,
"plugins": ["prettier-plugin-svelte"],
"pluginSearchDirs": ["."],
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
}

View File

@@ -1,37 +1,23 @@
{
"name": "sveltekit-nextauth",
"private": true,
"version": "0.0.1",
"scripts": {
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
},
"devDependencies": {
"@fontsource/fira-mono": "^4.5.10",
"@neoconfetti/svelte": "^1.0.0",
"@sveltejs/adapter-auto": "next",
"@sveltejs/kit": "next",
"@types/cookie": "^0.5.1",
"@typescript-eslint/eslint-plugin": "^5.45.0",
"@typescript-eslint/parser": "^5.45.0",
"eslint": "^8.28.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-svelte3": "^4.0.0",
"prettier": "^2.8.0",
"prettier-plugin-svelte": "^2.8.1",
"svelte": "^3.54.0",
"svelte-check": "^2.9.2",
"tslib": "^2.4.1",
"typescript": "^4.9.3",
"vite": "^4.0.0"
},
"dependencies": {
"cookie": "0.5.0",
"@auth/core": "workspace:*",
"@auth/sveltekit": "workspace:^"
},
"type": "module"
"scripts": {
"dev": "vite dev",
"build": "vite build",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
},
"devDependencies": {
"@sveltejs/adapter-auto": "next",
"@sveltejs/kit": "next",
"svelte": "3.55.0",
"svelte-check": "2.10.2",
"typescript": "4.9.4",
"vite": "4.0.1"
},
"dependencies": {
"cookie": "0.5.0",
"@auth/core": "workspace:*",
"@auth/sveltekit": "workspace:*"
},
"type": "module"
}

View File

@@ -1,32 +1 @@
/// <reference types="@sveltejs/kit" />
/// <reference types="next-auth-sveltekit" />
import type {
User as NextAuthUser,
Session as NextAuthSession,
} from "next-auth"
// optionally extend the `user`
interface User extends NextAuthUser {
// add custom fields here
}
interface AppSession extends NextAuthSession {
user: User
}
// See https://kit.svelte.dev/docs/typescript
// for information about these interfaces
declare global {
declare namespace App {
interface Locals {
// session: AppSession
getSession: () => Promise<AppSession>
}
interface Platform {}
interface Session extends AppSession {}
interface Stuff {}
}
}
/// <reference types="@auth/sveltekit" />

View File

@@ -1,15 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.ico" />
<meta name="viewport" content="width=device-width" />
%sveltekit.head%
</head>
<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.ico" />
<meta name="viewport" content="width=device-width" />
%sveltekit.head%
</head>
<body>
<div>%sveltekit.body%</div>
</body>
</html>
<body>
<div>%sveltekit.body%</div>
</body>
</html>

View File

@@ -1,25 +1,7 @@
import SvelteKitAuth from "@auth/sveltekit"
import GitHub from '@auth/core/providers/github';
import Google from '@auth/core/providers/google';
import Credentials from '@auth/core/providers/credentials';
import {
GITHUB_CLIENT_ID,
GITHUB_CLIENT_SECRET,
GOOGLE_CLIENT_ID,
GOOGLE_CLIENT_SECRET,
} from "$env/static/private"
import GitHub from "@auth/core/providers/github"
import { GITHUB_ID, GITHUB_SECRET } from "$env/static/private"
export const handle = SvelteKitAuth({
providers: [
GitHub({ clientId: GITHUB_CLIENT_ID, clientSecret: GITHUB_CLIENT_SECRET }),
Google({ clientId: GOOGLE_CLIENT_ID, clientSecret: GOOGLE_CLIENT_SECRET }),
Credentials({
credentials: { password: { label: "Password", type: "password" } },
async authorize(credentials) {
if (credentials.password !== "pw") return null
return { name: "Fill Murray", email: "bill@fillmurray.com", image: "https://www.fillmurray.com/64/64", id: "1", foo: "" }
},
}),
],
debug: true,
});
providers: [GitHub({ clientId: GITHUB_ID, clientSecret: GITHUB_SECRET })],
})

View File

@@ -1,12 +1,12 @@
<script lang="ts">
export let provider: any;
export let provider: any
</script>
<form action={provider.signinUrl} method="POST">
{#if provider.callbackUrl}
<input type="hidden" name="callbackUrl" value={provider.callbackUrl} />
{/if}
<button type="submit" class="button">
<slot>Sign in with {provider.name}</slot>
</button>
{#if provider.callbackUrl}
<input type="hidden" name="callbackUrl" value={provider.callbackUrl} />
{/if}
<button type="submit" class="button">
<slot>Sign in with {provider.name}</slot>
</button>
</form>

View File

@@ -1,14 +1,7 @@
import type { LayoutServerLoad } from "./$types"
export const load: LayoutServerLoad = (event) => {
console.log('layout server load', event.locals.getSession)
let session
if (event.locals.getSession)
{
session = event.locals.getSession()
}
export const load: LayoutServerLoad = async (event) => {
return {
session,
session: await event.locals.getSession(),
}
}

View File

@@ -1,144 +1,151 @@
<script lang="ts">
import { page } from '$app/stores';
import { page } from "$app/stores"
</script>
<div>
<header>
<div class="signedInStatus">
<p class="nojs-show loaded">
{#if Object.keys($page.data.session || {}).length}
{#if $page.data.session.user.image}
<span style="background-image: url('{$page.data.session.user.image}')" class="avatar" />
{/if}
<span class="signedInText">
<small>Signed in as</small><br />
<strong>{$page.data.session.user.email || $page.data.session.user.name}</strong>
</span>
<a href="/auth/signout" class="button">Sign out</a>
{:else}
<span class="notSignedInText">You are not signed in</span>
<a href="/auth/signin" class="buttonPrimary">Sign in</a>
{/if}
</p>
</div>
<nav>
<ul class="navItems">
<li class="navItem"><a href="/">Home</a></li>
<li class="navItem"><a href="/protected">Protected</a></li>
</ul>
</nav>
</header>
<slot />
<header>
<div class="signedInStatus">
<p class="nojs-show loaded">
{#if $page.data.session}
{#if $page.data.session.user?.image}
<span
style="background-image: url('{$page.data.session.user.image}')"
class="avatar"
/>
{/if}
<span class="signedInText">
<small>Signed in as</small><br />
<strong
>{$page.data.session.user?.email ??
$page.data.session.user?.name}</strong
>
</span>
<a href="/auth/signout" class="button">Sign out</a>
{:else}
<span class="notSignedInText">You are not signed in</span>
<a href="/auth/signin" class="buttonPrimary">Sign in</a>
{/if}
</p>
</div>
<nav>
<ul class="navItems">
<li class="navItem"><a href="/">Home</a></li>
<li class="navItem"><a href="/protected">Protected</a></li>
</ul>
</nav>
</header>
<slot />
</div>
<style>
:global(body) {
font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji',
'Segoe UI Symbol', 'Noto Color Emoji';
padding: 0 1rem 1rem 1rem;
max-width: 680px;
margin: 0 auto;
background: #fff;
color: #333;
}
:global(li),
:global(p) {
line-height: 1.5rem;
}
:global(a) {
font-weight: 500;
}
:global(hr) {
border: 1px solid #ddd;
}
:global(iframe) {
background: #ccc;
border: 1px solid #ccc;
height: 10rem;
width: 100%;
border-radius: 0.5rem;
filter: invert(1);
}
:global(body) {
font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif,
"Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol",
"Noto Color Emoji";
padding: 0 1rem 1rem 1rem;
max-width: 680px;
margin: 0 auto;
background: #fff;
color: #333;
}
:global(li),
:global(p) {
line-height: 1.5rem;
}
:global(a) {
font-weight: 500;
}
:global(hr) {
border: 1px solid #ddd;
}
:global(iframe) {
background: #ccc;
border: 1px solid #ccc;
height: 10rem;
width: 100%;
border-radius: 0.5rem;
filter: invert(1);
}
.nojs-show {
opacity: 1;
top: 0;
}
.signedInStatus {
display: block;
min-height: 4rem;
width: 100%;
}
.loaded {
position: relative;
top: 0;
opacity: 1;
overflow: hidden;
border-radius: 0 0 0.6rem 0.6rem;
padding: 0.6rem 1rem;
margin: 0;
background-color: rgba(0, 0, 0, 0.05);
transition: all 0.2s ease-in;
}
.signedInText,
.notSignedInText {
position: absolute;
padding-top: 0.8rem;
left: 1rem;
right: 6.5rem;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
display: inherit;
z-index: 1;
line-height: 1.3rem;
}
.signedInText {
padding-top: 0rem;
left: 4.6rem;
}
.avatar {
border-radius: 2rem;
float: left;
height: 2.8rem;
width: 2.8rem;
background-color: white;
background-size: cover;
background-repeat: no-repeat;
}
.button,
.buttonPrimary {
float: right;
margin-right: -0.4rem;
font-weight: 500;
border-radius: 0.3rem;
cursor: pointer;
font-size: 1rem;
line-height: 1.4rem;
padding: 0.7rem 0.8rem;
position: relative;
z-index: 10;
background-color: transparent;
color: #555;
}
.buttonPrimary {
background-color: #346df1;
border-color: #346df1;
color: #fff;
text-decoration: none;
padding: 0.7rem 1.4rem;
}
.buttonPrimary:hover {
box-shadow: inset 0 0 5rem rgba(0, 0, 0, 0.2);
}
.navItems {
margin-bottom: 2rem;
padding: 0;
list-style: none;
}
.navItem {
display: inline-block;
margin-right: 1rem;
}
.nojs-show {
opacity: 1;
top: 0;
}
.signedInStatus {
display: block;
min-height: 4rem;
width: 100%;
}
.loaded {
position: relative;
top: 0;
opacity: 1;
overflow: hidden;
border-radius: 0 0 0.6rem 0.6rem;
padding: 0.6rem 1rem;
margin: 0;
background-color: rgba(0, 0, 0, 0.05);
transition: all 0.2s ease-in;
}
.signedInText,
.notSignedInText {
position: absolute;
padding-top: 0.8rem;
left: 1rem;
right: 6.5rem;
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
display: inherit;
z-index: 1;
line-height: 1.3rem;
}
.signedInText {
padding-top: 0rem;
left: 4.6rem;
}
.avatar {
border-radius: 2rem;
float: left;
height: 2.8rem;
width: 2.8rem;
background-color: white;
background-size: cover;
background-repeat: no-repeat;
}
.button,
.buttonPrimary {
float: right;
margin-right: -0.4rem;
font-weight: 500;
border-radius: 0.3rem;
cursor: pointer;
font-size: 1rem;
line-height: 1.4rem;
padding: 0.7rem 0.8rem;
position: relative;
z-index: 10;
background-color: transparent;
color: #555;
}
.buttonPrimary {
background-color: #346df1;
border-color: #346df1;
color: #fff;
text-decoration: none;
padding: 0.7rem 1.4rem;
}
.buttonPrimary:hover {
box-shadow: inset 0 0 5rem rgba(0, 0, 0, 0.2);
}
.navItems {
margin-bottom: 2rem;
padding: 0;
list-style: none;
}
.navItem {
display: inline-block;
margin-right: 1rem;
}
</style>

View File

@@ -1,25 +1,33 @@
<script>
import { signIn, signOut } from '@auth/sveltekit/client';
import { page } from '$app/stores';
import { signIn, signOut } from "@auth/sveltekit/client"
import { page } from "$app/stores"
</script>
<h1>SvelteKit + NextAuth.js Example</h1>
<h1>SvelteKit Auth Example</h1>
<p>
This is an example site to demonstrate how to use <a href="https://kit.svelte.dev/">SvelteKit</a>
with <a href="https://next-auth.js.org">NextAuth.js</a> for authentication.
This is an example site to demonstrate how to use <a
href="https://kit.svelte.dev/">SvelteKit</a
>
with <a href="https://sveltekit.authjs.dev">SvelteKit Auth</a> for
authentication.
{#if Object.keys($page.data.session || {}).length}
{#if $page.data.session.user.image}
<span style="background-image: url('{$page.data.session.user.image}')" class="avatar" />
{/if}
<span class="signedInText">
<small>Signed in as</small><br />
<strong>{$page.data.session.user.email || $page.data.session.user.name}</strong>
</span>
<button on:click={() => signOut()} class="button">Sign out</button>
{:else}
<span class="notSignedInText">You are not signed in</span>
<button on:click={() => signIn('github')}>Sign In with GitHub</button>
<button on:click={() => signIn('credentials', { redirect: false })}>Sign In credentials</button>
{/if}
{#if $page.data.session}
{#if $page.data.session.user?.image}
<span
style="background-image: url('{$page.data.session.user.image}')"
class="avatar"
/>
{/if}
<span class="signedInText">
<small>Signed in as</small><br />
<strong
>{$page.data.session.user?.email ??
$page.data.session.user?.name}</strong
>
</span>
<button on:click={() => signOut()} class="button">Sign out</button>
{:else}
<span class="notSignedInText">You are not signed in</span>
<button on:click={() => signIn("github")}>Sign In with GitHub</button>
{/if}
</p>

View File

@@ -7,4 +7,4 @@
This is a protected content. You can access this content because you are
signed in.
</p>
<p>Session expiry: {$page.data.session.expires}</p>
<p>Session expiry: {$page.data.session?.expires}</p>

View File

@@ -14,4 +14,4 @@
//
// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
// from the referenced tsconfig.json - TypeScript does not merge them in
}
}

View File

@@ -1,8 +1,8 @@
import { sveltekit } from '@sveltejs/kit/vite';
import { sveltekit } from "@sveltejs/kit/vite"
/** @type {import('vite').UserConfig} */
const config = {
plugins: [sveltekit()]
};
plugins: [sveltekit()],
}
export default config;
export default config

View File

@@ -5,7 +5,7 @@
"repository": "https://github.com/nextauthjs/next-auth.git",
"scripts": {
"build:app": "turbo run build --filter=next-auth-app",
"build": "turbo run build --filter=next-auth --filter=@next-auth/* --no-deps",
"build": "turbo run build --filter=next-auth --filter=@next-auth/* --filter=@auth/* --no-deps",
"lint": "turbo run lint --filter=!next-auth-docs --parallel",
"test": "turbo run test --concurrency=1 --filter=!@next-auth/pouchdb-adapter --filter=!@next-auth/upstash-redis-adapter --filter=!next-auth-* --filter=[HEAD^1]",
"clean": "turbo run clean --no-cache",
@@ -32,7 +32,7 @@
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^6.0.0",
"husky": "^7.0.4",
"prettier": "2.7.1",
"prettier": "2.8.1",
"pretty-quick": "^3.1.2",
"semver": "7.3.5",
"stream-to-array": "2.3.0",

View File

@@ -1,8 +1,8 @@
{
"name": "@auth/core",
"version": "0.1.1",
"version": "0.1.3",
"description": "Authentication for the web.",
"homepage": "https://next-auth.js.org",
"homepage": "https://authjs.dev",
"repository": "https://github.com/nextauthjs/next-auth.git",
"author": "Balázs Orbán <info@balazsorban.com>",
"contributors": [
@@ -44,7 +44,7 @@
"@panva/hkdf": "1.0.2",
"cookie": "0.5.0",
"jose": "4.11.1",
"oauth4webapi": "2.0.4",
"oauth4webapi": "2.0.5",
"preact": "10.11.3",
"preact-render-to-string": "5.2.3"
},

View File

@@ -56,7 +56,7 @@ export function assertConfig(params: {
}
if (!options.secret) {
return new MissingSecret("Please define a `secret` in production.")
return new MissingSecret("Please define a `secret`.")
}
// req.query isn't defined when asserting `unstable_getServerSession` for example

View File

@@ -1,5 +1,4 @@
import type { InternalProvider, Theme } from "../.."
import type { CSSProperties } from "react"
/**
* The following errors are passed as error query parameters to the default or overridden sign-in page.
@@ -92,15 +91,12 @@ export default function SigninPage(props: SignInServerPageParams) {
<button
type="submit"
className="button"
style={
// eslint-disable-next-line
{
"--provider-bg": provider.style?.bg ?? "",
"--provider-dark-bg": provider.style?.bgDark ?? "",
"--provider-color": provider.style?.text ?? "",
"--provider-dark-color": provider.style?.textDark ?? "",
} as CSSProperties
}
style={{
"--provider-bg": provider.style?.bg ?? "",
"--provider-dark-bg": provider.style?.bgDark ?? "",
"--provider-color": provider.style?.text ?? "",
"--provider-dark-color": provider.style?.textDark ?? "",
}}
>
{provider.style?.logo && (
<img

View File

@@ -5,6 +5,7 @@
"baseUrl": ".",
"isolatedModules": true,
"jsx": "react-jsx",
"jsxImportSource": "preact",
"lib": [
"dom",
"dom.iterable",

View File

@@ -7,7 +7,7 @@ module.exports = {
"prettier",
],
plugins: ["svelte3", "@typescript-eslint"],
ignorePatterns: ["*.cjs"],
ignorePatterns: ["*.cjs", "client.*", "index.*"],
overrides: [{ files: ["*.svelte"], processor: "svelte3/svelte3" }],
settings: {
"svelte3/typescript": () => require("typescript"),

View File

@@ -3,11 +3,5 @@ node_modules
/build
/.svelte-kit
/package
.env
.env.*
!.env.example
# Ignore files for PNPM, NPM and YARN
pnpm-lock.yaml
package-lock.json
yarn.lock
/index.*
/client.*

View File

@@ -1,3 +1,3 @@
# SvelteKit Auth
Authentication for SvelteKit.
Authentication for SvelteKit.

View File

@@ -1,6 +1,9 @@
{
"name": "@auth/sveltekit",
"version": "0.1.1",
"version": "0.1.4",
"description": "Authentication for SvelteKit.",
"homepage": "https://sveltekit.authjs.dev",
"repository": "https://github.com/nextauthjs/next-auth.git",
"author": "Thang Huu Vu <hi@thvu.dev>",
"contributors": [
"Thang Huu Vu <hi@thvu.dev>",
@@ -12,7 +15,7 @@
"scripts": {
"dev": "svelte-package -w",
"clean": "rm -rf client.* index.* package",
"build": "pnpm clean && svelte-package && node ./scripts/postbuild.js && rm -rf package",
"build": "pnpm clean && pnpm check && svelte-package && node ./scripts/postbuild.js && rm -rf package",
"preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
@@ -31,7 +34,7 @@
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-svelte3": "^4.0.0",
"next-auth": "workspace:*",
"prettier": "^2.8.0",
"prettier": "2.8.1",
"prettier-plugin-svelte": "^2.8.1",
"svelte": "^3.54.0",
"svelte-check": "^2.9.2",

View File

@@ -1,20 +0,0 @@
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
/// <reference types="@sveltejs/kit" />
// See https://kit.svelte.dev/docs/types#app
// for information about these interfaces
// and what to do when importing types
declare namespace App {
// interface Error {}
interface Locals {
getSession: () => Promise<unknown>
}
// interface PageData {}
// interface Platform {}
}
declare module "$env/static/private" {
export const AUTH_SECRET: string
export const AUTH_TRUST_HOST: string
export const VERCEL: string
}

View File

@@ -1,12 +1,20 @@
import { AUTH_SECRET, AUTH_TRUST_HOST, VERCEL } from "$env/static/private"
/// <reference types="@sveltejs/kit" />
import { dev } from "$app/environment"
import { AUTH_SECRET, AUTH_TRUST_HOST, VERCEL } from "$env/static/private"
import {
AuthHandler,
type AuthAction,
type AuthOptions,
type Session,
} from "@auth/core"
import type { Handle } from "@sveltejs/kit"
import { AuthHandler, type AuthOptions, type AuthAction } from "@auth/core"
export type GetSessionResult = Promise<Session | null>
export async function getServerSession(
export async function getSession(
req: Request,
options: AuthOptions
): Promise<unknown> {
): GetSessionResult {
options.secret ??= AUTH_SECRET
options.trustHost ??= true
@@ -21,15 +29,13 @@ export async function getServerSession(
const data = await response.json()
if (!data || !Object.keys(data).length) return null
if (status === 200) {
return data
}
if (status === 200) return data
throw new Error(data.message)
}
interface SvelteKitAuthOptions extends AuthOptions {
export interface SvelteKitAuthOptions extends AuthOptions {
/**
* Defines the base path for the auth routes.
* @default '/auth'
*/
prefix?: string
@@ -47,25 +53,53 @@ const actions: AuthAction[] = [
"_log",
]
/** The main entry point to @auth/sveltekit */
function SvelteKitAuth({ prefix = "/auth", ...options }: SvelteKitAuthOptions) {
options.secret ??= AUTH_SECRET
options.trustHost ??= !!(AUTH_TRUST_HOST ?? VERCEL ?? dev)
function SvelteKitAuthHandler(
prefix: string,
authOptions: AuthOptions
): Handle {
return ({ event, resolve }) => {
const { url, request } = event
return (({ event, resolve }) => {
const [action] = event.url.pathname.slice(prefix.length + 1).split("/")
const isAuth = actions.includes(action as AuthAction)
event.locals.getSession ??= () => getSession(request, authOptions)
if (!event.locals.getSession)
event.locals.getSession = async () =>
getServerSession(event.request, options)
if (!event.url.pathname.startsWith(prefix + "/") || !isAuth) {
return resolve(event)
const [action] = url.pathname.slice(prefix.length + 1).split("/")
if (
actions.includes(action as AuthAction) &&
url.pathname.startsWith(prefix + "/")
) {
return AuthHandler(request, authOptions)
}
return AuthHandler(event.request, options)
}) satisfies Handle
return resolve(event)
}
}
export default SvelteKitAuth
/**
* The main entry point to `@auth/sveltekit`
* @see https://sveltekit.authjs.dev
*/
export default function SvelteKitAuth(options: SvelteKitAuthOptions): Handle {
const { prefix = "/auth", ...authOptions } = options
authOptions.secret ??= AUTH_SECRET
authOptions.trustHost ??= !!(AUTH_TRUST_HOST ?? VERCEL ?? dev)
return SvelteKitAuthHandler(prefix, authOptions)
}
declare global {
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace App {
interface Locals {
getSession: () => GetSessionResult
}
interface PageData {
session: Session | null
}
}
}
declare module "$env/static/private" {
export const AUTH_SECRET: string
export const AUTH_TRUST_HOST: string
export const VERCEL: string
}

View File

@@ -1,5 +1,5 @@
{
// "extends": "./.svelte-kit/tsconfig.json",
"extends": "./.svelte-kit/tsconfig.json",
"compilerOptions": {
"allowJs": true,
"checkJs": true,
@@ -8,12 +8,11 @@
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"moduleResolution": "node"
"strict": true
},
// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
//
// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
// from the referenced tsconfig.json - TypeScript does not merge them in
"exclude": ["scripts", "*.js", ".svelte-kit"]
"exclude": ["scripts", "*.js", "../node_modules/**", "./[!ambient.d.ts]**"]
}

259
pnpm-lock.yaml generated
View File

@@ -21,7 +21,7 @@ importers:
eslint-plugin-node: ^11.1.0
eslint-plugin-promise: ^6.0.0
husky: ^7.0.4
prettier: 2.7.1
prettier: 2.8.1
pretty-quick: ^3.1.2
semver: 7.3.5
stream-to-array: 2.3.0
@@ -43,8 +43,8 @@ importers:
eslint-plugin-node: 11.1.0_eslint@7.32.0
eslint-plugin-promise: 6.0.0_eslint@7.32.0
husky: 7.0.4
prettier: 2.7.1
pretty-quick: 3.1.3_prettier@2.7.1
prettier: 2.8.1
pretty-quick: 3.1.3_prettier@2.8.1
semver: 7.3.5
stream-to-array: 2.3.0
ts-node: 10.5.0_ksn4eycaeggbrckn3ykh37hwf4
@@ -101,46 +101,24 @@ importers:
apps/playground-sveltekit:
specifiers:
'@auth/core': workspace:*
'@auth/sveltekit': workspace:^
'@fontsource/fira-mono': ^4.5.10
'@neoconfetti/svelte': ^1.0.0
'@auth/sveltekit': workspace:*
'@sveltejs/adapter-auto': next
'@sveltejs/kit': next
'@types/cookie': ^0.5.1
'@typescript-eslint/eslint-plugin': ^5.45.0
'@typescript-eslint/parser': ^5.45.0
cookie: 0.5.0
eslint: ^8.28.0
eslint-config-prettier: ^8.5.0
eslint-plugin-svelte3: ^4.0.0
prettier: ^2.8.0
prettier-plugin-svelte: ^2.8.1
svelte: ^3.54.0
svelte-check: ^2.9.2
tslib: ^2.4.1
typescript: ^4.9.3
vite: ^4.0.0
svelte: 3.55.0
svelte-check: 2.10.2
typescript: 4.9.4
vite: 4.0.1
dependencies:
'@auth/core': link:../../packages/core
'@auth/sveltekit': link:../../packages/frameworks-sveltekit
cookie: 0.5.0
devDependencies:
'@fontsource/fira-mono': 4.5.10
'@neoconfetti/svelte': 1.0.0
'@sveltejs/adapter-auto': 1.0.0-next.90
'@sveltejs/kit': 1.0.0-next.586_svelte@3.54.0+vite@4.0.1
'@types/cookie': 0.5.1
'@typescript-eslint/eslint-plugin': 5.45.1_tdm6ms4ntwhlpozn7kjqrhum74
'@typescript-eslint/parser': 5.45.1_s5ps7njkmjlaqajutnox5ntcla
eslint: 8.29.0
eslint-config-prettier: 8.5.0_eslint@8.29.0
eslint-plugin-svelte3: 4.0.0_2aagxyyd66x6iymg5nfckajqjq
prettier: 2.8.0
prettier-plugin-svelte: 2.8.1_kaioqtfwjumrsfopsgfoca65re
svelte: 3.54.0
svelte-check: 2.10.1_svelte@3.54.0
tslib: 2.4.1
typescript: 4.9.3
'@sveltejs/adapter-auto': 1.0.0-next.91_oogoraclbppcquiitsbqrelvd4
'@sveltejs/kit': 1.0.0-next.587_svelte@3.55.0+vite@4.0.1
svelte: 3.55.0
svelte-check: 2.10.2_svelte@3.55.0
typescript: 4.9.4
vite: 4.0.1
docs:
@@ -496,7 +474,7 @@ importers:
cookie: 0.5.0
cssnano: 5.1.14
jose: 4.11.1
oauth4webapi: 2.0.4
oauth4webapi: 2.0.5
postcss: 8.4.19
postcss-nested: 6.0.0
preact: 10.11.3
@@ -505,7 +483,7 @@ importers:
'@panva/hkdf': 1.0.2
cookie: 0.5.0
jose: 4.11.1
oauth4webapi: 2.0.4
oauth4webapi: 2.0.5
preact: 10.11.3
preact-render-to-string: 5.2.3_preact@10.11.3
devDependencies:
@@ -531,7 +509,7 @@ importers:
eslint-config-prettier: ^8.5.0
eslint-plugin-svelte3: ^4.0.0
next-auth: workspace:*
prettier: ^2.8.0
prettier: 2.8.1
prettier-plugin-svelte: ^2.8.1
svelte: ^3.54.0
svelte-check: ^2.9.2
@@ -543,8 +521,8 @@ importers:
'@auth/core': link:../core
devDependencies:
'@playwright/test': 1.28.1
'@sveltejs/adapter-auto': 1.0.0-next.90
'@sveltejs/kit': 1.0.0-next.586_svelte@3.54.0+vite@4.0.1
'@sveltejs/adapter-auto': 1.0.0-next.91_oogoraclbppcquiitsbqrelvd4
'@sveltejs/kit': 1.0.0-next.587_svelte@3.54.0+vite@4.0.1
'@sveltejs/package': 1.0.0-next.6_gf4dcx76vtk2o62ixxeqx7chra
'@typescript-eslint/eslint-plugin': 5.45.1_tdm6ms4ntwhlpozn7kjqrhum74
'@typescript-eslint/parser': 5.45.1_s5ps7njkmjlaqajutnox5ntcla
@@ -552,8 +530,8 @@ importers:
eslint-config-prettier: 8.5.0_eslint@8.29.0
eslint-plugin-svelte3: 4.0.0_2aagxyyd66x6iymg5nfckajqjq
next-auth: link:../next-auth
prettier: 2.8.0
prettier-plugin-svelte: 2.8.1_kaioqtfwjumrsfopsgfoca65re
prettier: 2.8.1
prettier-plugin-svelte: 2.8.1_sro2v6ld777payjtkjtiuogcxi
svelte: 3.54.0
svelte-check: 2.10.1_svelte@3.54.0
tslib: 2.4.1
@@ -5800,7 +5778,7 @@ packages:
infima: 0.2.0-alpha.42
lodash: 4.17.21
nprogress: 0.2.0
postcss: 8.4.19
postcss: 8.4.20
prism-react-renderer: 1.3.5_react@18.2.0
prismjs: 1.28.0
react: 18.2.0
@@ -6794,10 +6772,6 @@ packages:
resolution: {integrity: sha512-CJW8vxt6bJaBeco2VnlJjmCmAkrrtIdf0GGKvpAB4J5gw8Gi0rHb+qsgKp6LsyS5W6ALPLawLs7phZmw02dvLw==}
dev: true
/@fontsource/fira-mono/4.5.10:
resolution: {integrity: sha512-bxUnRP8xptGRo8YXeY073DSpfK74XpSb0ZyRNpHV9WvLnJ7TwPOjZll8hTMin7zLC6iOp59pDZ8EQDj1gzgAQQ==}
dev: true
/@gar/promisify/1.1.3:
resolution: {integrity: sha512-k2Ty1JcVojjJFwrg/ThKi2ujJ7XNLYaFGNB/bWT9wGR+oSMJHMa5w+CUq6p/pVrKeNNgA7pCqEcjSnHVoqJQFw==}
dev: true
@@ -7670,10 +7644,6 @@ packages:
'@jridgewell/trace-mapping': 0.3.17
dev: true
/@jridgewell/sourcemap-codec/1.4.13:
resolution: {integrity: sha512-GryiOJmNcWbovBxTfZSF71V/mXbgcV3MewDe3kIMCLyIh5e7SKAeUZs+rMnJ8jkMolZ/4/VsdBmMrw3l+VdZ3w==}
dev: true
/@jridgewell/sourcemap-codec/1.4.14:
resolution: {integrity: sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw==}
@@ -7681,7 +7651,7 @@ packages:
resolution: {integrity: sha512-o1xbKhp9qnIAoHJSWd6KlCZfqslL4valSF81H8ImioOAxluWYWOpWkpyktY2vnt4tbrX9XYaxovq6cgowaJp2w==}
dependencies:
'@jridgewell/resolve-uri': 3.0.7
'@jridgewell/sourcemap-codec': 1.4.13
'@jridgewell/sourcemap-codec': 1.4.14
dev: true
/@jridgewell/trace-mapping/0.3.17:
@@ -7897,10 +7867,6 @@ packages:
- supports-color
dev: true
/@neoconfetti/svelte/1.0.0:
resolution: {integrity: sha512-SmksyaJAdSlMa9cTidVSIqYo1qti+WTsviNDwgjNVm+KQ3DRP2Df9umDIzC4vCcpEYY+chQe0i2IKnLw03AT8Q==}
dev: true
/@next/env/13.0.6:
resolution: {integrity: sha512-yceT6DCHKqPRS1cAm8DHvDvK74DLIkDQdm5iV+GnIts8h0QbdHvkUIkdOvQoOODgpr6018skbmSQp12z5OWIQQ==}
@@ -8297,14 +8263,17 @@ packages:
- encoding
- supports-color
/@sveltejs/adapter-auto/1.0.0-next.90:
resolution: {integrity: sha512-qxH46Oqqn40998wTmnbffONI0HcW/kiZ3OIjZoysjONne+LU4uEsG425MZ2RHDxmR04zxhsdjCAsn6B4du8D7w==}
/@sveltejs/adapter-auto/1.0.0-next.91_oogoraclbppcquiitsbqrelvd4:
resolution: {integrity: sha512-U57tQdzTfFINim8tzZSARC9ztWPzwOoHwNOpGdb2o6XrD0mEQwU9DsII7dBblvzg+xCnmd0pw7PDtXz5c5t96w==}
peerDependencies:
'@sveltejs/kit': ^1.0.0-next.587
dependencies:
'@sveltejs/kit': 1.0.0-next.587_svelte@3.54.0+vite@4.0.1
import-meta-resolve: 2.2.0
dev: true
/@sveltejs/kit/1.0.0-next.586_svelte@3.54.0+vite@4.0.1:
resolution: {integrity: sha512-lTYWy4voh/r4jz8qnurIATyrH2ZgHPUswYQ9KauyASSjQGYeB1TPDgwcafM/LtgMxpcvFgWsx2KeflykSHXKxg==}
/@sveltejs/kit/1.0.0-next.587_svelte@3.54.0+vite@4.0.1:
resolution: {integrity: sha512-F8zYXd7URcq57sGfrBRWTLtfj6JKkhNhwM4M8w4hNnJsJlZawPUvpybOSlIP87Z8URO8iCmyigQHxAYYzedrOg==}
engines: {node: '>=16.14'}
hasBin: true
requiresBuild: true
@@ -8331,6 +8300,34 @@ packages:
- supports-color
dev: true
/@sveltejs/kit/1.0.0-next.587_svelte@3.55.0+vite@4.0.1:
resolution: {integrity: sha512-F8zYXd7URcq57sGfrBRWTLtfj6JKkhNhwM4M8w4hNnJsJlZawPUvpybOSlIP87Z8URO8iCmyigQHxAYYzedrOg==}
engines: {node: '>=16.14'}
hasBin: true
requiresBuild: true
peerDependencies:
svelte: ^3.54.0
vite: ^4.0.0
dependencies:
'@sveltejs/vite-plugin-svelte': 2.0.0_svelte@3.55.0+vite@4.0.1
'@types/cookie': 0.5.1
cookie: 0.5.0
devalue: 4.2.0
esm-env: 1.0.0
kleur: 4.1.5
magic-string: 0.27.0
mime: 3.0.0
sade: 1.8.1
set-cookie-parser: 2.5.1
sirv: 2.0.2
svelte: 3.55.0
tiny-glob: 0.2.9
undici: 5.11.0
vite: 4.0.1
transitivePeerDependencies:
- supports-color
dev: true
/@sveltejs/package/1.0.0-next.6_gf4dcx76vtk2o62ixxeqx7chra:
resolution: {integrity: sha512-EwekVYRnD1r0deTt+9OKRvDopdX59FdfMVV+sN/LtIRO8+mEYuuDkj4uurt5yA9o2sMsv9xiAIWT5qKrq0rXuQ==}
engines: {node: '>=16.14'}
@@ -8366,6 +8363,25 @@ packages:
- supports-color
dev: true
/@sveltejs/vite-plugin-svelte/2.0.0_svelte@3.55.0+vite@4.0.1:
resolution: {integrity: sha512-oUFrYQarRv4fppmxdrv00qw3wX8Ycdj0uv33MfpRZyR8K67dyxiOcHnqkB0zSy5sDJA8RC/2aNtYhXJ8NINVHQ==}
engines: {node: ^14.18.0 || >= 16}
peerDependencies:
svelte: ^3.54.0
vite: ^4.0.0
dependencies:
debug: 4.3.4
deepmerge: 4.2.2
kleur: 4.1.5
magic-string: 0.27.0
svelte: 3.55.0
svelte-hmr: 0.15.1_svelte@3.55.0
vite: 4.0.1
vitefu: 0.2.2_vite@4.0.1
transitivePeerDependencies:
- supports-color
dev: true
/@svgr/babel-plugin-add-jsx-attribute/6.0.0_@babel+core@7.20.2:
resolution: {integrity: sha512-MdPdhdWLtQsjd29Wa4pABdhWbaRMACdM1h31BY+c6FghTZqNGT7pEYdBoaGeKtdTOBC/XNFQaKVj+r/Ei2ryWA==}
engines: {node: '>=10'}
@@ -20465,8 +20481,8 @@ packages:
resolution: {integrity: sha512-a5ERWK1kh38ExDEfoO6qUHJb32rd7aYmPHuyCu3Fta/cnICvYmgd2uhuKXvPD+PXB+gCEYYEaQdIRAjCOwAKNA==}
dev: false
/oauth4webapi/2.0.4:
resolution: {integrity: sha512-d6NmQuOlCo6+HzNPG70Pl8T4WnHo/XPvQ3Dxus3fRvRjFmt9H+BggI/APyzQ4/jlcdIjPaOw81wIO6WkRGKfkg==}
/oauth4webapi/2.0.5:
resolution: {integrity: sha512-KmoR3KxCwmr9KvL/c/6UVzQnc4CUjo+j8NSgD3bWYlZXpUmyOVw97nDVb0BKZhCcUtGsbll16v8vsnR5JbTZ9A==}
dev: false
/object-assign/4.1.1:
@@ -22365,13 +22381,13 @@ packages:
engines: {node: '>=4'}
dev: true
/prettier-plugin-svelte/2.8.1_kaioqtfwjumrsfopsgfoca65re:
/prettier-plugin-svelte/2.8.1_sro2v6ld777payjtkjtiuogcxi:
resolution: {integrity: sha512-KA3K1J3/wKDnCxW7ZDRA/QL2Q67N7Xs3gOERqJ5X1qFjq1DdnN3K1R29scSKwh+kA8FF67pXbYytUpvN/i3iQw==}
peerDependencies:
prettier: ^1.16.4 || ^2.0.0
svelte: ^3.2.0
dependencies:
prettier: 2.8.0
prettier: 2.8.1
svelte: 3.54.0
dev: true
@@ -22381,8 +22397,8 @@ packages:
hasBin: true
dev: true
/prettier/2.8.0:
resolution: {integrity: sha512-9Lmg8hTFZKG0Asr/kW9Bp8tJjRVluO8EJQVfY2T7FMw9T5jy4I/Uvx0Rca/XWf50QQ1/SS48+6IJWnrb+2yemA==}
/prettier/2.8.1:
resolution: {integrity: sha512-lqGoSJBQNJidqCHE80vqZJHWHRFoNYsSpP9AjFhlhi9ODCJA541svILes/+/1GM3VaL/abZi7cpFzOpdR9UPKg==}
engines: {node: '>=10.13.0'}
hasBin: true
dev: true
@@ -22451,7 +22467,7 @@ packages:
engines: {node: '>= 0.8'}
dev: true
/pretty-quick/3.1.3_prettier@2.7.1:
/pretty-quick/3.1.3_prettier@2.8.1:
resolution: {integrity: sha512-kOCi2FJabvuh1as9enxYmrnBC6tVMoVOenMaBqRfsvBHB0cbpYHjdQEpSglpASDFEXVwplpcGR4CLEaisYAFcA==}
engines: {node: '>=10.13'}
hasBin: true
@@ -22464,7 +22480,7 @@ packages:
ignore: 5.2.0
mri: 1.2.0
multimatch: 4.0.0
prettier: 2.7.1
prettier: 2.8.1
dev: true
/pretty-time/1.1.0:
@@ -24684,8 +24700,36 @@ packages:
picocolors: 1.0.0
sade: 1.8.1
svelte: 3.54.0
svelte-preprocess: 4.10.7_gf4dcx76vtk2o62ixxeqx7chra
typescript: 4.9.3
svelte-preprocess: 4.10.7_vjccw6zkwqrmxudvmy4reaayx4
typescript: 4.9.4
transitivePeerDependencies:
- '@babel/core'
- coffeescript
- less
- node-sass
- postcss
- postcss-load-config
- pug
- sass
- stylus
- sugarss
dev: true
/svelte-check/2.10.2_svelte@3.55.0:
resolution: {integrity: sha512-h1Tuiir0m8J5yqN+Vx6qgKKk1L871e6a9o7rMwVWfu8Qs6Wg7x2R+wcxS3SO3VpW5JCxCat90rxPsZMYgz+HaQ==}
hasBin: true
peerDependencies:
svelte: ^3.24.0
dependencies:
'@jridgewell/trace-mapping': 0.3.17
chokidar: 3.5.3
fast-glob: 3.2.11
import-fresh: 3.3.0
picocolors: 1.0.0
sade: 1.8.1
svelte: 3.55.0
svelte-preprocess: 4.10.7_niwyv7xychq2ag6arq5eqxbomm
typescript: 4.9.4
transitivePeerDependencies:
- '@babel/core'
- coffeescript
@@ -24708,7 +24752,67 @@ packages:
svelte: 3.54.0
dev: true
/svelte-preprocess/4.10.7_gf4dcx76vtk2o62ixxeqx7chra:
/svelte-hmr/0.15.1_svelte@3.55.0:
resolution: {integrity: sha512-BiKB4RZ8YSwRKCNVdNxK/GfY+r4Kjgp9jCLEy0DuqAKfmQtpL38cQK3afdpjw4sqSs4PLi3jIPJIFp259NkZtA==}
engines: {node: ^12.20 || ^14.13.1 || >= 16}
peerDependencies:
svelte: '>=3.19.0'
dependencies:
svelte: 3.55.0
dev: true
/svelte-preprocess/4.10.7_niwyv7xychq2ag6arq5eqxbomm:
resolution: {integrity: sha512-sNPBnqYD6FnmdBrUmBCaqS00RyCsCpj2BG58A1JBswNF7b0OKviwxqVrOL/CKyJrLSClrSeqQv5BXNg2RUbPOw==}
engines: {node: '>= 9.11.2'}
requiresBuild: true
peerDependencies:
'@babel/core': ^7.10.2
coffeescript: ^2.5.1
less: ^3.11.3 || ^4.0.0
node-sass: '*'
postcss: ^7 || ^8
postcss-load-config: ^2.1.0 || ^3.0.0 || ^4.0.0
pug: ^3.0.0
sass: ^1.26.8
stylus: ^0.55.0
sugarss: ^2.0.0
svelte: ^3.23.0
typescript: ^3.9.5 || ^4.0.0
peerDependenciesMeta:
'@babel/core':
optional: true
coffeescript:
optional: true
less:
optional: true
node-sass:
optional: true
postcss:
optional: true
postcss-load-config:
optional: true
pug:
optional: true
sass:
optional: true
stylus:
optional: true
sugarss:
optional: true
typescript:
optional: true
dependencies:
'@types/pug': 2.0.6
'@types/sass': 1.43.1
detect-indent: 6.1.0
magic-string: 0.25.9
sorcery: 0.10.0
strip-indent: 3.0.0
svelte: 3.55.0
typescript: 4.9.4
dev: true
/svelte-preprocess/4.10.7_vjccw6zkwqrmxudvmy4reaayx4:
resolution: {integrity: sha512-sNPBnqYD6FnmdBrUmBCaqS00RyCsCpj2BG58A1JBswNF7b0OKviwxqVrOL/CKyJrLSClrSeqQv5BXNg2RUbPOw==}
engines: {node: '>= 9.11.2'}
requiresBuild: true
@@ -24756,7 +24860,7 @@ packages:
sorcery: 0.10.0
strip-indent: 3.0.0
svelte: 3.54.0
typescript: 4.9.3
typescript: 4.9.4
dev: true
/svelte/3.54.0:
@@ -24764,6 +24868,11 @@ packages:
engines: {node: '>= 8'}
dev: true
/svelte/3.55.0:
resolution: {integrity: sha512-uGu2FVMlOuey4JoKHKrpZFkoYyj0VLjJdz47zX5+gVK5odxHM40RVhar9/iK2YFRVxvfg9FkhfVlR0sjeIrOiA==}
engines: {node: '>= 8'}
dev: true
/svelte2tsx/0.5.22_gf4dcx76vtk2o62ixxeqx7chra:
resolution: {integrity: sha512-OytIql7Bv53oFuL0jjsnp/gNvR4ngAUdAjswgibmIQT2Lj2OIQYn2J3gKqRd+wSj/n3M/wrz4zJpudQRSfncZw==}
peerDependencies:
@@ -25757,6 +25866,12 @@ packages:
hasBin: true
dev: true
/typescript/4.9.4:
resolution: {integrity: sha512-Uz+dTXYzxXXbsFpM86Wh3dKCxrQqUcVMxwU54orwlJjOpO3ao8L7j5lH+dWfTwgCwIuM9GQ2kvVotzYJMXTBZg==}
engines: {node: '>=4.2.0'}
hasBin: true
dev: true
/ua-parser-js/0.7.31:
resolution: {integrity: sha512-qLK/Xe9E2uzmYI3qLeOmI0tEOt+TBBQyUIAh4aAgU05FVYzeZrKUdkAZfBNVGRaHVgV0TDkdEngJSw/SyQchkQ==}
dev: true