Skip to content

Commit e17cc71

Browse files
ndom91balazsorban44destructo570Maronato
authored
feat(sveltekit): webauthn provider support (#9924)
Co-authored-by: Balázs Orbán <[email protected]> Co-authored-by: Vishal Kashi <[email protected]> Co-authored-by: Gustavo Maronato <[email protected]> Co-authored-by: Gustavo Maronato <[email protected]>
1 parent 89ef33f commit e17cc71

File tree

14 files changed

+532
-29
lines changed

14 files changed

+532
-29
lines changed

apps/dev/sveltekit/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ node_modules
1010
.output
1111
vite.config.js.timestamp-*
1212
vite.config.ts.timestamp-*
13+
tmp-unstorage

apps/dev/sveltekit/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
"dependencies": {
2222
"@auth/sveltekit": "workspace:*",
2323
"@auth/unstorage-adapter": "workspace:*",
24-
"nodemailer": "^6.9.3",
25-
"unstorage": "^1.10.1"
24+
"unstorage": "^1.10.2"
2625
},
2726
"type": "module"
2827
}

apps/dev/sveltekit/src/auth.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,21 @@ import Credentials from "@auth/sveltekit/providers/credentials"
44
import Facebook from "@auth/sveltekit/providers/facebook"
55
import Discord from "@auth/sveltekit/providers/discord"
66
import Google from "@auth/sveltekit/providers/google"
7+
import Passkey from "@auth/sveltekit/providers/passkey"
78
import { createStorage } from "unstorage"
89
import { UnstorageAdapter } from "@auth/unstorage-adapter"
10+
import fsDriver from "unstorage/drivers/fs"
11+
import { dev } from "$app/environment"
12+
13+
const storage = createStorage({
14+
driver: fsDriver({ base: "./tmp-unstorage" }),
15+
})
916

10-
const storage = createStorage()
1117
export const { handle, signIn, signOut } = SvelteKitAuth({
12-
debug: true,
18+
debug: dev ? true : false,
1319
adapter: UnstorageAdapter(storage),
14-
session: {
15-
strategy: "jwt",
20+
experimental: {
21+
enableWebAuthn: true,
1622
},
1723
providers: [
1824
Credentials({
@@ -31,6 +37,7 @@ export const { handle, signIn, signOut } = SvelteKitAuth({
3137
Google,
3238
Facebook,
3339
Discord,
40+
Passkey,
3441
],
3542
theme: {
3643
logo: "https://authjs.dev/img/logo-sm.png",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { signIn } from "../../auth"
1+
import { signIn } from "$/auth"
22
import type { Actions } from "./$types"
33

44
export const actions = { default: signIn } satisfies Actions
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { signOut } from "../../auth"
1+
import { signOut } from "$/auth"
22
import type { Actions } from "./$types"
33

44
export const actions = { default: signOut } satisfies Actions

apps/dev/sveltekit/vite.config.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1+
import { defineConfig } from "vite"
12
import { sveltekit } from "@sveltejs/kit/vite"
23

3-
/** @type {import('vite').UserConfig} */
4-
const config = {
4+
export default defineConfig({
55
server: {
66
port: 3000,
77
},
88
plugins: [sveltekit()],
9-
}
10-
11-
export default config
9+
})

docs/pages/getting-started/providers/passkey.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ as any database adapter that plans to support it. Therefore, the WebAuthn provid
1717
is currently only supported in the following framework integration and database adapters.
1818
Support for more frameworks and adapters are coming soon.{" "}
1919

20-
- `[email protected]` or above
20+
- `[email protected]` or above
21+
- `@auth/[email protected]` or above
2122
- `@auth/[email protected]` or above
22-
- `@prisma/client@5.9.1` or above
23+
- `@prisma/client@5.12.0` or above
2324

2425
<Steps>
2526
### Install peer dependencies

packages/core/src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ import type {
7373
WebAuthnProviderType,
7474
} from "./providers/webauthn.js"
7575

76+
export type { WebAuthnOptionsResponseBody } from "./lib/utils/webauthn-utils.js"
77+
export type { AuthConfig } from "./index.js"
7678
export type { LoggerInstance }
7779
export type Awaitable<T> = T | PromiseLike<T>
7880
export type Awaited<T> = T extends Promise<infer U> ? U : T

packages/frameworks-sveltekit/package.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,23 @@
5050
"set-cookie-parser": "^2.6.0"
5151
},
5252
"peerDependencies": {
53+
"@simplewebauthn/browser": "^9.0.1",
54+
"@simplewebauthn/server": "^9.0.3",
5355
"@sveltejs/kit": "^1.0.0 || ^2.0.0",
56+
"nodemailer": "^6.6.5",
5457
"svelte": "^3.54.0 || ^4.0.0 || ^5"
5558
},
59+
"peerDependenciesMeta": {
60+
"@simplewebauthn/browser": {
61+
"optional": true
62+
},
63+
"@simplewebauthn/server": {
64+
"optional": true
65+
},
66+
"nodemailer": {
67+
"optional": true
68+
}
69+
},
5670
"type": "module",
5771
"types": "./dist/index.d.ts",
5872
"files": [
@@ -68,6 +82,10 @@
6882
"types": "./dist/client.d.ts",
6983
"import": "./dist/client.js"
7084
},
85+
"./webauthn": {
86+
"types": "./dist/webauthn.d.ts",
87+
"import": "./dist/webauthn.js"
88+
},
7189
"./components": {
7290
"types": "./dist/components/index.d.ts",
7391
"svelte": "./dist/components/index.js"

packages/frameworks-sveltekit/src/lib/client.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
import { base } from "$app/paths"
12
import type {
23
BuiltInProviderType,
34
RedirectableProviderType,
45
} from "@auth/core/providers"
5-
import { base } from "$app/paths"
6+
import type { LiteralUnion } from "./types.js"
67

7-
type LiteralUnion<T extends U, U = string> = T | (U & Record<never, never>)
8-
9-
interface SignInOptions extends Record<string, unknown> {
8+
/*
9+
* @internal
10+
*/
11+
export interface SignInOptions extends Record<string, unknown> {
1012
/**
1113
* Specify to which URL the user will be redirected after signing in. Defaults to the page URL the sign-in is initiated from.
1214
*

0 commit comments

Comments
 (0)