You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+60Lines changed: 60 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,6 +23,7 @@ Add Authentication to Nuxt applications with secured & sealed cookies sessions.
23
23
-[Tree-shakable server utils](#server-utils)
24
24
-[`<AuthState>` component](#authstate-component)
25
25
-[Extendable with hooks](#extend-session)
26
+
-[WebSocket support](#websockets-support)
26
27
27
28
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.
28
29
@@ -596,6 +597,65 @@ You can use the `placeholder` slot to show a placeholder on server-side and whil
596
597
597
598
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.
598
599
600
+
## WebSockets Support
601
+
602
+
Nuxt Auth Utils is compatible with [Nitro WebSockets](https://nitro.build/guide/websocket).
603
+
604
+
Make sure to enable the `experimental.websocket` option in your `nuxt.config.ts`:
605
+
606
+
```ts
607
+
exportdefaultdefineNuxtConfig({
608
+
nitro: {
609
+
experimental: {
610
+
websocket: true
611
+
}
612
+
}
613
+
})
614
+
```
615
+
616
+
You can use the `requireUserSession` function in the `upgrade` function to check if the user is authenticated before upgrading the WebSocket connection.
617
+
618
+
```ts
619
+
// server/routes/ws.ts
620
+
exportdefaultdefineWebSocketHandler({
621
+
async upgrade(request) {
622
+
// Make sure the user is authenticated before upgrading the WebSocket connection
0 commit comments