Skip to content

Commit b4699fa

Browse files
ThangHuuVundom91balazsorban44
authored
feat: add server signIn and signOut methods (#9714)
* feat: add server signin and signout methods * chore: upgrade svelte-package * feat: add example of usages * chore: format package * chore: apply code review * fix: build * feat: update svelte dev app .env.example * feat: poc form actions * add SignOut * Update package.json * fix: sign-in -> signin and update SignInButton component css * fix: don't hide signout behind email address * chore: merge main * feat: add custom signin page to sveltekit dev app * fix: redirect is a thrown error, so no need to return * fix: point custom login page back to '/signin' * merge main * use isAuthAction from core * chore: move fake-smtp-server to top level * feat: correctly parse authorizationParams and options in SignIn * refactor: use unstorage * chore: use env inferrence * Update package.json Co-authored-by: Balázs Orbán <[email protected]> * return for consistency * add restProps for form components * Update package.json * tweak * tweak dev app * documentation --------- Co-authored-by: ndom91 <[email protected]> Co-authored-by: Balázs Orbán <[email protected]>
1 parent b2ca9fe commit b4699fa

File tree

24 files changed

+698
-678
lines changed

24 files changed

+698
-678
lines changed

apps/dev/nextjs/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
"dev": "next dev",
99
"build": "next build",
1010
"start": "next start",
11-
"email": "fake-smtp-server",
12-
"start:email": "pnpm email",
1311
"e2e": "pnpm dlx playwright test"
1412
},
1513
"license": "ISC",
@@ -25,7 +23,6 @@
2523
"devDependencies": {
2624
"@types/react": "^18.2.23",
2725
"@types/react-dom": "^18.2.8",
28-
"fake-smtp-server": "^0.8.0",
2926
"prisma": "^5",
3027
"sqlite3": "^5.0.8"
3128
}

apps/dev/sveltekit/.env.example

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
GITHUB_ID=
2-
GITHUB_SECRET=
1+
AUTH_GITHUB_ID=
2+
AUTH_GITHUB_SECRET=
33
# On UNIX systems you can use `openssl rand -hex 32` or
44
# https://generate-secret.vercel.app/32 to generate a secret.
5-
AUTH_SECRET=
5+
AUTH_SECRET=

apps/dev/sveltekit/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
"vite": "^5"
2121
},
2222
"dependencies": {
23-
"@auth/sveltekit": "workspace:*"
23+
"@auth/sveltekit": "workspace:*",
24+
"@auth/unstorage-adapter": "workspace:*",
25+
"nodemailer": "^6.9.3",
26+
"unstorage": "^1.10.1"
2427
},
2528
"type": "module"
26-
}
29+
}

apps/dev/sveltekit/src/auth.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { SvelteKitAuth } from "@auth/sveltekit"
2+
import GitHub from "@auth/sveltekit/providers/github"
3+
import Credentials from "@auth/sveltekit/providers/credentials"
4+
import Facebook from "@auth/sveltekit/providers/facebook"
5+
import Auth0 from "@auth/sveltekit/providers/auth0"
6+
import Discord from "@auth/sveltekit/providers/discord"
7+
import Email from "@auth/sveltekit/providers/email"
8+
import Google from "@auth/sveltekit/providers/google"
9+
import Twitter from "@auth/sveltekit/providers/twitter"
10+
import LinkedIn from "@auth/sveltekit/providers/linkedin"
11+
import Instagram from "@auth/sveltekit/providers/instagram"
12+
import Okta from "@auth/sveltekit/providers/okta"
13+
import Apple from "@auth/sveltekit/providers/apple"
14+
import Slack from "@auth/sveltekit/providers/slack"
15+
import Twitch from "@auth/sveltekit/providers/twitch"
16+
import Cognito from "@auth/sveltekit/providers/cognito"
17+
import AzureAD from "@auth/sveltekit/providers/azure-ad"
18+
import Reddit from "@auth/sveltekit/providers/reddit"
19+
import Spotify from "@auth/sveltekit/providers/spotify"
20+
import SendGrid from "@auth/sveltekit/providers/sendgrid"
21+
import { createStorage } from "unstorage"
22+
import { UnstorageAdapter } from "@auth/unstorage-adapter"
23+
24+
25+
const storage = createStorage()
26+
export const { handle, signIn, signOut } = SvelteKitAuth({
27+
adapter: UnstorageAdapter(storage),
28+
session: {
29+
strategy: "jwt",
30+
},
31+
providers: [
32+
SendGrid,
33+
Email({ server: "smtps://0.0.0.0:465?tls.rejectUnauthorized=false" }),
34+
Credentials({
35+
credentials: { password: { label: "Password", type: "password" } },
36+
async authorize(credentials) {
37+
if (credentials.password !== "pw") return null
38+
return {
39+
name: "Fill Murray",
40+
41+
image: "https://www.fillmurray.com/64/64",
42+
id: "1",
43+
foo: "",
44+
}
45+
},
46+
}),
47+
Google,
48+
Facebook,
49+
GitHub,
50+
Discord,
51+
Twitter,
52+
Slack,
53+
LinkedIn,
54+
Okta,
55+
Apple,
56+
Auth0,
57+
Spotify,
58+
Instagram,
59+
Cognito,
60+
Twitch,
61+
Reddit,
62+
AzureAD,
63+
],
64+
theme: {
65+
logo: "https://authjs.dev/img/logo/logo-sm.webp",
66+
},
67+
})
Lines changed: 1 addition & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -1,159 +1 @@
1-
import { SvelteKitAuth } from "@auth/sveltekit"
2-
import GitHub from "@auth/sveltekit/providers/github"
3-
import Credentials from "@auth/sveltekit/providers/credentials"
4-
import Facebook from "@auth/sveltekit/providers/facebook"
5-
import Auth0 from "@auth/sveltekit/providers/auth0"
6-
import Discord from "@auth/sveltekit/providers/discord"
7-
import Email from "@auth/sveltekit/providers/email"
8-
import Google from "@auth/sveltekit/providers/google"
9-
import Twitter from "@auth/sveltekit/providers/twitter"
10-
import LinkedIn from "@auth/sveltekit/providers/linkedin"
11-
import Instagram from "@auth/sveltekit/providers/instagram"
12-
import Okta from "@auth/sveltekit/providers/okta"
13-
import Apple from "@auth/sveltekit/providers/apple"
14-
import Slack from "@auth/sveltekit/providers/slack"
15-
import Twitch from "@auth/sveltekit/providers/twitch"
16-
import Cognito from "@auth/sveltekit/providers/cognito"
17-
import AzureAD from "@auth/sveltekit/providers/azure-ad"
18-
import Reddit from "@auth/sveltekit/providers/reddit"
19-
import Spotify from "@auth/sveltekit/providers/spotify"
20-
import {
21-
GITHUB_ID,
22-
GITHUB_SECRET,
23-
FACEBOOK_ID,
24-
FACEBOOK_SECRET,
25-
AUTH0_ID,
26-
AUTH0_SECRET,
27-
AUTH0_ISSUER,
28-
DISCORD_ID,
29-
DISCORD_SECRET,
30-
GOOGLE_ID,
31-
GOOGLE_SECRET,
32-
TWITTER_ID,
33-
TWITTER_SECRET,
34-
LINKEDIN_ID,
35-
LINKEDIN_SECRET,
36-
INSTAGRAM_ID,
37-
INSTAGRAM_SECRET,
38-
OKTA_ID,
39-
OKTA_SECRET,
40-
OKTA_ISSUER,
41-
APPLE_ID,
42-
APPLE_SECRET,
43-
SLACK_ID,
44-
SLACK_SECRET,
45-
TWITCH_ID,
46-
TWITCH_SECRET,
47-
COGNITO_ID,
48-
COGNITO_SECRET,
49-
COGNITO_ISSUER,
50-
AZURE_AD_ID,
51-
AZURE_AD_SECRET,
52-
REDDIT_ID,
53-
REDDIT_SECRET,
54-
SPOTIFY_ID,
55-
SPOTIFY_SECRET,
56-
} from "$env/static/private"
57-
import { TestAdapter } from "$lib/adapter"
58-
59-
const db: Record<string, any> = {}
60-
61-
const adapter = TestAdapter({
62-
getItem(key) {
63-
return db[key]
64-
},
65-
setItem: function (key: string, value: string): Promise<void> {
66-
db[key] = value
67-
return Promise.resolve()
68-
},
69-
deleteItems: function (...keys: string[]): Promise<void> {
70-
keys.forEach((key) => delete db[key])
71-
return Promise.resolve()
72-
},
73-
})
74-
export const handle = SvelteKitAuth({
75-
adapter,
76-
session: {
77-
strategy: "jwt",
78-
},
79-
providers: [
80-
Email({ server: "smtp://127.0.0.1:1025?tls.rejectUnauthorized=false" }),
81-
Credentials({
82-
credentials: { password: { label: "Password", type: "password" } },
83-
async authorize(credentials) {
84-
if (credentials.password !== "pw") return null
85-
return {
86-
name: "Fill Murray",
87-
88-
image: "https://www.fillmurray.com/64/64",
89-
id: "1",
90-
foo: "",
91-
}
92-
},
93-
}),
94-
Google({
95-
clientId: GOOGLE_ID,
96-
clientSecret: GOOGLE_SECRET,
97-
}),
98-
Facebook({ clientId: FACEBOOK_ID, clientSecret: FACEBOOK_SECRET }),
99-
GitHub({ clientId: GITHUB_ID, clientSecret: GITHUB_SECRET }),
100-
Discord({
101-
clientId: DISCORD_ID,
102-
clientSecret: DISCORD_SECRET,
103-
}),
104-
Twitter({
105-
clientId: TWITTER_ID,
106-
clientSecret: TWITTER_SECRET,
107-
}),
108-
Slack({
109-
clientId: SLACK_ID,
110-
clientSecret: SLACK_SECRET,
111-
}),
112-
LinkedIn({
113-
clientId: LINKEDIN_ID,
114-
clientSecret: LINKEDIN_SECRET,
115-
}),
116-
Okta({
117-
clientId: OKTA_ID,
118-
clientSecret: OKTA_SECRET,
119-
issuer: OKTA_ISSUER,
120-
}),
121-
Apple({
122-
clientId: APPLE_ID,
123-
clientSecret: APPLE_SECRET,
124-
}),
125-
Auth0({
126-
clientId: AUTH0_ID,
127-
clientSecret: AUTH0_SECRET,
128-
issuer: AUTH0_ISSUER,
129-
}),
130-
Spotify({
131-
clientId: SPOTIFY_ID,
132-
clientSecret: SPOTIFY_SECRET,
133-
}),
134-
Instagram({
135-
clientId: INSTAGRAM_ID,
136-
clientSecret: INSTAGRAM_SECRET,
137-
}),
138-
Cognito({
139-
clientId: COGNITO_ID,
140-
clientSecret: COGNITO_SECRET,
141-
issuer: COGNITO_ISSUER,
142-
}),
143-
Twitch({
144-
clientId: TWITCH_ID,
145-
clientSecret: TWITCH_SECRET,
146-
}),
147-
Reddit({
148-
clientId: REDDIT_ID,
149-
clientSecret: REDDIT_SECRET,
150-
}),
151-
AzureAD({
152-
clientId: AZURE_AD_ID,
153-
clientSecret: AZURE_AD_SECRET,
154-
}),
155-
],
156-
theme: {
157-
logo: "https://authjs.dev/img/logo/logo-sm.webp",
158-
},
159-
})
1+
export { handle } from "./auth"

apps/dev/sveltekit/src/lib/SignInButton.svelte

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)