Skip to content

Commit e5ec5f1

Browse files
Merge branch 'main' into feature/add-server-side-session-storage
2 parents d9a7d8e + 42a2a7a commit e5ec5f1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+5675
-3590
lines changed

.github/workflows/ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ jobs:
6565
- name: Run test suite
6666
run: pnpm test
6767

68-
- name: Test types
69-
run: pnpm test:types
68+
# - name: Test types
69+
# run: pnpm test:types
7070

7171
# - name: Test playground types
7272
# run: pnpm test:types:playground

CHANGELOG.md

+215
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,221 @@
11
# Changelog
22

33

4+
## v0.5.10
5+
6+
[compare changes](https://github.com/atinux/nuxt-auth-utils/compare/v0.5.9...v0.5.10)
7+
8+
### 🚀 Enhancements
9+
10+
- Add apple provider ([#328](https://github.com/atinux/nuxt-auth-utils/pull/328))
11+
12+
### 📖 Documentation
13+
14+
- Typo ([8b132e4](https://github.com/atinux/nuxt-auth-utils/commit/8b132e4))
15+
- Improve example ([9d191a1](https://github.com/atinux/nuxt-auth-utils/commit/9d191a1))
16+
17+
### ❤️ Contributors
18+
19+
- David ([@GreenmeisterDavid](http://github.com/GreenmeisterDavid))
20+
- Sébastien Chopin ([@atinux](http://github.com/atinux))
21+
22+
## v0.5.9
23+
24+
[compare changes](https://github.com/atinux/nuxt-auth-utils/compare/v0.5.8...v0.5.9)
25+
26+
### 🚀 Enhancements
27+
28+
- Add support for websocket handler ([#327](https://github.com/atinux/nuxt-auth-utils/pull/327))
29+
30+
### ❤️ Contributors
31+
32+
- Sébastien Chopin ([@atinux](http://github.com/atinux))
33+
34+
## v0.5.8
35+
36+
[compare changes](https://github.com/atinux/nuxt-auth-utils/compare/v0.5.7...v0.5.8)
37+
38+
### 🚀 Enhancements
39+
40+
- Self-hosted Gitlab instances ([#323](https://github.com/atinux/nuxt-auth-utils/pull/323))
41+
- Add Line OAuth provider ([#312](https://github.com/atinux/nuxt-auth-utils/pull/312))
42+
- Add atlassian oauth-provider ([#307](https://github.com/atinux/nuxt-auth-utils/pull/307), [#308](https://github.com/atinux/nuxt-auth-utils/pull/308))
43+
44+
### 🩹 Fixes
45+
46+
- Add discord oauth error ([#316](https://github.com/atinux/nuxt-auth-utils/pull/316))
47+
- Normalise errors when user not accessible ([c98ea5d](https://github.com/atinux/nuxt-auth-utils/commit/c98ea5d))
48+
49+
### 🏡 Chore
50+
51+
- Disable test:types ([ec9b727](https://github.com/atinux/nuxt-auth-utils/commit/ec9b727))
52+
- Rename jtw to jwt ([#326](https://github.com/atinux/nuxt-auth-utils/pull/326))
53+
- Update deps ([9cd39e8](https://github.com/atinux/nuxt-auth-utils/commit/9cd39e8))
54+
55+
### ❤️ Contributors
56+
57+
- Sébastien Chopin <[email protected]>
58+
- Jonas ([@jonasfroeller](http://github.com/jonasfroeller))
59+
- Devskillpro ([@devskillpro](http://github.com/devskillpro))
60+
- Exit ([@exitss](http://github.com/exitss))
61+
- Benjamin Stauß <[email protected]>
62+
- Thijs Wijnmaalen <[email protected]>
63+
64+
## v0.5.7
65+
66+
[compare changes](https://github.com/atinux/nuxt-auth-utils/compare/v0.5.6...v0.5.7)
67+
68+
### 🚀 Enhancements
69+
70+
- Keycloak internal server URL ([ac61ae5](https://github.com/atinux/nuxt-auth-utils/commit/ac61ae5))
71+
- **cognito:** Integrate OpenID Connect discovery for improved OAuth flow ([7a01cc3](https://github.com/atinux/nuxt-auth-utils/commit/7a01cc3))
72+
- Add hubspot provider ([1a79baf](https://github.com/atinux/nuxt-auth-utils/commit/1a79baf))
73+
74+
### 🩹 Fixes
75+
76+
- Make sure the required env is checked ([#306](https://github.com/atinux/nuxt-auth-utils/pull/306))
77+
78+
### 🏡 Chore
79+
80+
- Lint fix ([3532d48](https://github.com/atinux/nuxt-auth-utils/commit/3532d48))
81+
- Update deps ([f6f6b71](https://github.com/atinux/nuxt-auth-utils/commit/f6f6b71))
82+
- Update deps ([7d09be5](https://github.com/atinux/nuxt-auth-utils/commit/7d09be5))
83+
- Lint fix ([c9a3716](https://github.com/atinux/nuxt-auth-utils/commit/c9a3716))
84+
85+
### ❤️ Contributors
86+
87+
- Sébastien Chopin ([@atinux](http://github.com/atinux))
88+
- Guilherme Guimarães <[email protected]>
89+
- Gage Keenan ([@kilakewe](http://github.com/kilakewe))
90+
- Carl Gödecken ([@MasterCarl](http://github.com/MasterCarl))
91+
92+
## v0.5.6
93+
94+
[compare changes](https://github.com/atinux/nuxt-auth-utils/compare/v0.5.5...v0.5.6)
95+
96+
### 🚀 Enhancements
97+
98+
- Adding `organization_id` option for WorkOS provider ([677b226](https://github.com/atinux/nuxt-auth-utils/commit/677b226))
99+
- Add strava oauth provider ([96363b2](https://github.com/atinux/nuxt-auth-utils/commit/96363b2))
100+
101+
### 🩹 Fixes
102+
103+
- Seznam config ([90d0d18](https://github.com/atinux/nuxt-auth-utils/commit/90d0d18))
104+
- **instagram:** Oauth provider ([192e0e7](https://github.com/atinux/nuxt-auth-utils/commit/192e0e7))
105+
106+
### 🏡 Chore
107+
108+
- Update deps ([fb894bf](https://github.com/atinux/nuxt-auth-utils/commit/fb894bf))
109+
- Update deps" ([f4ef630](https://github.com/atinux/nuxt-auth-utils/commit/f4ef630))
110+
111+
### ❤️ Contributors
112+
113+
- Sébastien Chopin ([@atinux](http://github.com/atinux))
114+
- Sandro Circi ([@sandros94](http://github.com/sandros94))
115+
- Justpeterpan <[email protected]>
116+
- David Stranava ([@stranavad](http://github.com/stranavad))
117+
- Brian Coleman ([@brianacdev](http://github.com/brianacdev))
118+
119+
## v0.5.5
120+
121+
[compare changes](https://github.com/atinux/nuxt-auth-utils/compare/v0.5.4...v0.5.5)
122+
123+
### 🚀 Enhancements
124+
125+
- Add workos oauth provider ([bfa2a88](https://github.com/atinux/nuxt-auth-utils/commit/bfa2a88))
126+
- Add seznam oauth provider ([#285](https://github.com/atinux/nuxt-auth-utils/pull/285))
127+
- **webauthn:** Add event to validateUser to track authenticated users ([#287](https://github.com/atinux/nuxt-auth-utils/pull/287))
128+
129+
### 🏡 Chore
130+
131+
- Update packageManager to pnpm 9.13.2 ([fc0d991](https://github.com/atinux/nuxt-auth-utils/commit/fc0d991))
132+
133+
### ❤️ Contributors
134+
135+
- Sébastien Chopin ([@atinux](http://github.com/atinux))
136+
- David Stranava ([@stranavad](http://github.com/stranavad))
137+
- Brian Coleman <[email protected]>
138+
139+
## v0.5.4
140+
141+
[compare changes](https://github.com/atinux/nuxt-auth-utils/compare/v0.5.3...v0.5.4)
142+
143+
### 🚀 Enhancements
144+
145+
- Forward set-cookie header for `useUserSession().clear()` ([#282](https://github.com/atinux/nuxt-auth-utils/pull/282))
146+
147+
### 🏡 Chore
148+
149+
- Add SessionConfig type ([7633e27](https://github.com/atinux/nuxt-auth-utils/commit/7633e27))
150+
- Fix types ([5d58645](https://github.com/atinux/nuxt-auth-utils/commit/5d58645))
151+
- Update deps ([ffafb2c](https://github.com/atinux/nuxt-auth-utils/commit/ffafb2c))
152+
- Rename jtw to jwt ([139197b](https://github.com/atinux/nuxt-auth-utils/commit/139197b))
153+
154+
### ❤️ Contributors
155+
156+
- Sébastien Chopin ([@atinux](http://github.com/atinux))
157+
158+
## v0.5.3
159+
160+
[compare changes](https://github.com/atinux/nuxt-auth-utils/compare/v0.5.2...v0.5.3)
161+
162+
### 🚀 Enhancements
163+
164+
- Add authentik provider ([33686af](https://github.com/atinux/nuxt-auth-utils/commit/33686af))
165+
166+
### 🩹 Fixes
167+
168+
- **composable:** Use same context for `clear` and `fetch` ([#278](https://github.com/atinux/nuxt-auth-utils/pull/278))
169+
170+
### 🏡 Chore
171+
172+
- Update deps ([6072a74](https://github.com/atinux/nuxt-auth-utils/commit/6072a74))
173+
174+
### ❤️ Contributors
175+
176+
- Sébastien Chopin ([@atinux](http://github.com/atinux))
177+
- Aoor9 ([@aoor9](http://github.com/aoor9))
178+
179+
## v0.5.2
180+
181+
[compare changes](https://github.com/atinux/nuxt-auth-utils/compare/v0.5.1...v0.5.2)
182+
183+
### 🚀 Enhancements
184+
185+
- Zitadel provider implementation ([d4c0b5a](https://github.com/atinux/nuxt-auth-utils/commit/d4c0b5a))
186+
187+
### 🏡 Chore
188+
189+
- **release:** V0.5.1 ([727b5b4](https://github.com/atinux/nuxt-auth-utils/commit/727b5b4))
190+
- Fix package format ([247ec8f](https://github.com/atinux/nuxt-auth-utils/commit/247ec8f))
191+
- **playground:** Max height for dropdow ([10951b0](https://github.com/atinux/nuxt-auth-utils/commit/10951b0))
192+
- Update deps ([3e9422f](https://github.com/atinux/nuxt-auth-utils/commit/3e9422f))
193+
- **playground:** Update deps ([1d0d7f7](https://github.com/atinux/nuxt-auth-utils/commit/1d0d7f7))
194+
- Fix types ([a13b054](https://github.com/atinux/nuxt-auth-utils/commit/a13b054))
195+
196+
### ❤️ Contributors
197+
198+
- Sébastien Chopin ([@atinux](http://github.com/atinux))
199+
- Velka ([@Velka-DEV](http://github.com/Velka-DEV))
200+
201+
## v0.5.1
202+
203+
[compare changes](https://github.com/atinux/nuxt-auth-utils/compare/v0.5.0...v0.5.1)
204+
205+
### 🩹 Fixes
206+
207+
- `useWebAuthn` composable registration & fix `allowCredentials` / `excludeCredentials` option ([#266](https://github.com/atinux/nuxt-auth-utils/pull/266))
208+
209+
### 🏡 Chore
210+
211+
- **release:** V0.5.0 ([404acc6](https://github.com/atinux/nuxt-auth-utils/commit/404acc6))
212+
- Update deps ([8947e40](https://github.com/atinux/nuxt-auth-utils/commit/8947e40))
213+
214+
### ❤️ Contributors
215+
216+
- Sébastien Chopin ([@atinux](http://github.com/atinux))
217+
- Gerben Mulder <[email protected]>
218+
4219
## v0.5.0
5220

6221
[compare changes](https://github.com/atinux/nuxt-auth-utils/compare/v0.4.4...v0.5.0)

README.md

+85-5
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ Add Authentication to Nuxt applications with secured & sealed cookies sessions.
1616
## Features
1717

1818
- [Hybrid Rendering](#hybrid-rendering) support (SSR / CSR / SWR / Prerendering)
19-
- [20+ OAuth Providers](#supported-oauth-providers)
19+
- [30+ OAuth Providers](#supported-oauth-providers)
2020
- [Password Hashing](#password-hashing)
2121
- [WebAuthn (passkey)](#webauthn-passkey)
2222
- [`useUserSession()` Vue composable](#vue-composable)
2323
- [Tree-shakable server utils](#server-utils)
2424
- [`<AuthState>` component](#authstate-component)
2525
- [Extendable with hooks](#extend-session)
26+
- [WebSocket support](#websocket-support)
2627

2728
It has few dependencies (only from [UnJS](https://github.com/unjs)), run on multiple JS environments (Node, Deno, Workers) and is fully typed with TypeScript.
2829

@@ -204,7 +205,10 @@ It can also be set using environment variables:
204205
205206
#### Supported OAuth Providers
206207

208+
- Apple
209+
- Atlassian
207210
- Auth0
211+
- Authentik
208212
- AWS Cognito
209213
- Battle.net
210214
- Discord
@@ -213,21 +217,27 @@ It can also be set using environment variables:
213217
- GitHub
214218
- GitLab
215219
- Google
220+
- Hubspot
216221
- Instagram
217222
- Keycloak
223+
- Line
218224
- Linear
219225
- LinkedIn
220226
- Microsoft
221227
- PayPal
222228
- Polar
229+
- Seznam
223230
- Spotify
224231
- Steam
232+
- Strava
225233
- TikTok
226234
- Twitch
227235
- VK
236+
- WorkOS
228237
- X (Twitter)
229238
- XSUAA
230239
- Yandex
240+
- Zitadel
231241

232242
You can add your favorite provider by creating a new file in [src/runtime/server/lib/oauth/](./src/runtime/server/lib/oauth/).
233243

@@ -348,10 +358,21 @@ The following code does not include the actual database queries, but shows the g
348358
import { z } from 'zod'
349359
export default defineWebAuthnRegisterEventHandler({
350360
// optional
351-
validateUser: z.object({
352-
// we want the userName to be a valid email
353-
userName: z.string().email()
354-
}).parse,
361+
async validateUser(userBody, event) {
362+
// bonus: check if the user is already authenticated to link a credential to his account
363+
// We first check if the user is already authenticated by getting the session
364+
// And verify that the email is the same as the one in session
365+
const session = await getUserSession(event)
366+
if (session.user?.email && session.user.email !== body.userName) {
367+
throw createError({ statusCode: 400, message: 'Email not matching curent session' })
368+
}
369+
370+
// If he registers a new account with credentials
371+
return z.object({
372+
// we want the userName to be a valid email
373+
userName: z.string().email()
374+
}).parse(userBody)
375+
},
355376
async onSuccess(event, { credential, user }) {
356377
// The credential creation has been successful
357378
// We need to create a user if it does not exist
@@ -593,6 +614,65 @@ You can use the `placeholder` slot to show a placeholder on server-side and whil
593614

594615
If you are caching your routes with `routeRules`, please make sure to use [Nitro](https://github.com/unjs/nitro) >= `2.9.7` to support the client-side fetching of the user session.
595616

617+
## WebSocket Support
618+
619+
Nuxt Auth Utils is compatible with [Nitro WebSockets](https://nitro.build/guide/websocket).
620+
621+
Make sure to enable the `experimental.websocket` option in your `nuxt.config.ts`:
622+
623+
```ts
624+
export default defineNuxtConfig({
625+
nitro: {
626+
experimental: {
627+
websocket: true
628+
}
629+
}
630+
})
631+
```
632+
633+
You can use the `requireUserSession` function in the `upgrade` function to check if the user is authenticated before upgrading the WebSocket connection.
634+
635+
```ts
636+
// server/routes/ws.ts
637+
export default defineWebSocketHandler({
638+
async upgrade(request) {
639+
// Make sure the user is authenticated before upgrading the WebSocket connection
640+
await requireUserSession(request)
641+
},
642+
async open(peer) {
643+
const { user } = await requireUserSession(peer)
644+
645+
peer.send(`Hello, ${user.name}!`)
646+
},
647+
message(peer, message) {
648+
peer.send(`Echo: ${message}`)
649+
},
650+
})
651+
```
652+
653+
Then, in your application, you can use the [useWebSocket](https://vueuse.org/core/useWebSocket/) composable to connect to the WebSocket:
654+
655+
```vue
656+
<script setup>
657+
const { status, data, send, open, close } = useWebSocket('/ws', { immediate: false })
658+
659+
// Only open the websocket after the page is hydrated (client-only)
660+
onMounted(open)
661+
</script>
662+
663+
<template>
664+
<div>
665+
<p>Status: {{ status }}</p>
666+
<p>Data: {{ data }}</p>
667+
<p>
668+
<button @click="open">Open</button>
669+
<button @click="close(1000, 'Closing')">Close</button>
670+
<button @click="send('hello')">Send hello</button>
671+
</p>
672+
</div>
673+
</template>
674+
```
675+
596676
## Configuration
597677

598678
### Session Storage

0 commit comments

Comments
 (0)