Skip to content

Commit

Permalink
Merge branch 'main' into feature/add-server-side-session-storage
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-hofmann committed Jan 31, 2025
2 parents d9a7d8e + 42a2a7a commit 7a30d6b
Show file tree
Hide file tree
Showing 62 changed files with 5,676 additions and 3,591 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ jobs:
- name: Run test suite
run: pnpm test

- name: Test types
run: pnpm test:types
# - name: Test types
# run: pnpm test:types

# - name: Test playground types
# run: pnpm test:types:playground
215 changes: 215 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,221 @@
# Changelog


## v0.5.10

[compare changes](https://github.com/atinux/nuxt-auth-utils/compare/v0.5.9...v0.5.10)

### 🚀 Enhancements

- Add apple provider ([#328](https://github.com/atinux/nuxt-auth-utils/pull/328))

### 📖 Documentation

- Typo ([8b132e4](https://github.com/atinux/nuxt-auth-utils/commit/8b132e4))
- Improve example ([9d191a1](https://github.com/atinux/nuxt-auth-utils/commit/9d191a1))

### ❤️ Contributors

- David ([@GreenmeisterDavid](http://github.com/GreenmeisterDavid))
- Sébastien Chopin ([@atinux](http://github.com/atinux))

## v0.5.9

[compare changes](https://github.com/atinux/nuxt-auth-utils/compare/v0.5.8...v0.5.9)

### 🚀 Enhancements

- Add support for websocket handler ([#327](https://github.com/atinux/nuxt-auth-utils/pull/327))

### ❤️ Contributors

- Sébastien Chopin ([@atinux](http://github.com/atinux))

## v0.5.8

[compare changes](https://github.com/atinux/nuxt-auth-utils/compare/v0.5.7...v0.5.8)

### 🚀 Enhancements

- Self-hosted Gitlab instances ([#323](https://github.com/atinux/nuxt-auth-utils/pull/323))
- Add Line OAuth provider ([#312](https://github.com/atinux/nuxt-auth-utils/pull/312))
- Add atlassian oauth-provider ([#307](https://github.com/atinux/nuxt-auth-utils/pull/307), [#308](https://github.com/atinux/nuxt-auth-utils/pull/308))

### 🩹 Fixes

- Add discord oauth error ([#316](https://github.com/atinux/nuxt-auth-utils/pull/316))
- Normalise errors when user not accessible ([c98ea5d](https://github.com/atinux/nuxt-auth-utils/commit/c98ea5d))

### 🏡 Chore

- Disable test:types ([ec9b727](https://github.com/atinux/nuxt-auth-utils/commit/ec9b727))
- Rename jtw to jwt ([#326](https://github.com/atinux/nuxt-auth-utils/pull/326))
- Update deps ([9cd39e8](https://github.com/atinux/nuxt-auth-utils/commit/9cd39e8))

### ❤️ Contributors

- Sébastien Chopin <[email protected]>
- Jonas ([@jonasfroeller](http://github.com/jonasfroeller))
- Devskillpro ([@devskillpro](http://github.com/devskillpro))
- Exit ([@exitss](http://github.com/exitss))
- Benjamin Stauß <[email protected]>
- Thijs Wijnmaalen <[email protected]>

## v0.5.7

[compare changes](https://github.com/atinux/nuxt-auth-utils/compare/v0.5.6...v0.5.7)

### 🚀 Enhancements

- Keycloak internal server URL ([ac61ae5](https://github.com/atinux/nuxt-auth-utils/commit/ac61ae5))
- **cognito:** Integrate OpenID Connect discovery for improved OAuth flow ([7a01cc3](https://github.com/atinux/nuxt-auth-utils/commit/7a01cc3))
- Add hubspot provider ([1a79baf](https://github.com/atinux/nuxt-auth-utils/commit/1a79baf))

### 🩹 Fixes

- Make sure the required env is checked ([#306](https://github.com/atinux/nuxt-auth-utils/pull/306))

### 🏡 Chore

- Lint fix ([3532d48](https://github.com/atinux/nuxt-auth-utils/commit/3532d48))
- Update deps ([f6f6b71](https://github.com/atinux/nuxt-auth-utils/commit/f6f6b71))
- Update deps ([7d09be5](https://github.com/atinux/nuxt-auth-utils/commit/7d09be5))
- Lint fix ([c9a3716](https://github.com/atinux/nuxt-auth-utils/commit/c9a3716))

### ❤️ Contributors

- Sébastien Chopin ([@atinux](http://github.com/atinux))
- Guilherme Guimarães <[email protected]>
- Gage Keenan ([@kilakewe](http://github.com/kilakewe))
- Carl Gödecken ([@MasterCarl](http://github.com/MasterCarl))

## v0.5.6

[compare changes](https://github.com/atinux/nuxt-auth-utils/compare/v0.5.5...v0.5.6)

### 🚀 Enhancements

- Adding `organization_id` option for WorkOS provider ([677b226](https://github.com/atinux/nuxt-auth-utils/commit/677b226))
- Add strava oauth provider ([96363b2](https://github.com/atinux/nuxt-auth-utils/commit/96363b2))

### 🩹 Fixes

- Seznam config ([90d0d18](https://github.com/atinux/nuxt-auth-utils/commit/90d0d18))
- **instagram:** Oauth provider ([192e0e7](https://github.com/atinux/nuxt-auth-utils/commit/192e0e7))

### 🏡 Chore

- Update deps ([fb894bf](https://github.com/atinux/nuxt-auth-utils/commit/fb894bf))
- Update deps" ([f4ef630](https://github.com/atinux/nuxt-auth-utils/commit/f4ef630))

### ❤️ Contributors

- Sébastien Chopin ([@atinux](http://github.com/atinux))
- Sandro Circi ([@sandros94](http://github.com/sandros94))
- Justpeterpan <[email protected]>
- David Stranava ([@stranavad](http://github.com/stranavad))
- Brian Coleman ([@brianacdev](http://github.com/brianacdev))

## v0.5.5

[compare changes](https://github.com/atinux/nuxt-auth-utils/compare/v0.5.4...v0.5.5)

### 🚀 Enhancements

- Add workos oauth provider ([bfa2a88](https://github.com/atinux/nuxt-auth-utils/commit/bfa2a88))
- Add seznam oauth provider ([#285](https://github.com/atinux/nuxt-auth-utils/pull/285))
- **webauthn:** Add event to validateUser to track authenticated users ([#287](https://github.com/atinux/nuxt-auth-utils/pull/287))

### 🏡 Chore

- Update packageManager to pnpm 9.13.2 ([fc0d991](https://github.com/atinux/nuxt-auth-utils/commit/fc0d991))

### ❤️ Contributors

- Sébastien Chopin ([@atinux](http://github.com/atinux))
- David Stranava ([@stranavad](http://github.com/stranavad))
- Brian Coleman <[email protected]>

## v0.5.4

[compare changes](https://github.com/atinux/nuxt-auth-utils/compare/v0.5.3...v0.5.4)

### 🚀 Enhancements

- Forward set-cookie header for `useUserSession().clear()` ([#282](https://github.com/atinux/nuxt-auth-utils/pull/282))

### 🏡 Chore

- Add SessionConfig type ([7633e27](https://github.com/atinux/nuxt-auth-utils/commit/7633e27))
- Fix types ([5d58645](https://github.com/atinux/nuxt-auth-utils/commit/5d58645))
- Update deps ([ffafb2c](https://github.com/atinux/nuxt-auth-utils/commit/ffafb2c))
- Rename jtw to jwt ([139197b](https://github.com/atinux/nuxt-auth-utils/commit/139197b))

### ❤️ Contributors

- Sébastien Chopin ([@atinux](http://github.com/atinux))

## v0.5.3

[compare changes](https://github.com/atinux/nuxt-auth-utils/compare/v0.5.2...v0.5.3)

### 🚀 Enhancements

- Add authentik provider ([33686af](https://github.com/atinux/nuxt-auth-utils/commit/33686af))

### 🩹 Fixes

- **composable:** Use same context for `clear` and `fetch` ([#278](https://github.com/atinux/nuxt-auth-utils/pull/278))

### 🏡 Chore

- Update deps ([6072a74](https://github.com/atinux/nuxt-auth-utils/commit/6072a74))

### ❤️ Contributors

- Sébastien Chopin ([@atinux](http://github.com/atinux))
- Aoor9 ([@aoor9](http://github.com/aoor9))

## v0.5.2

[compare changes](https://github.com/atinux/nuxt-auth-utils/compare/v0.5.1...v0.5.2)

### 🚀 Enhancements

- Zitadel provider implementation ([d4c0b5a](https://github.com/atinux/nuxt-auth-utils/commit/d4c0b5a))

### 🏡 Chore

- **release:** V0.5.1 ([727b5b4](https://github.com/atinux/nuxt-auth-utils/commit/727b5b4))
- Fix package format ([247ec8f](https://github.com/atinux/nuxt-auth-utils/commit/247ec8f))
- **playground:** Max height for dropdow ([10951b0](https://github.com/atinux/nuxt-auth-utils/commit/10951b0))
- Update deps ([3e9422f](https://github.com/atinux/nuxt-auth-utils/commit/3e9422f))
- **playground:** Update deps ([1d0d7f7](https://github.com/atinux/nuxt-auth-utils/commit/1d0d7f7))
- Fix types ([a13b054](https://github.com/atinux/nuxt-auth-utils/commit/a13b054))

### ❤️ Contributors

- Sébastien Chopin ([@atinux](http://github.com/atinux))
- Velka ([@Velka-DEV](http://github.com/Velka-DEV))

## v0.5.1

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

### 🩹 Fixes

- `useWebAuthn` composable registration & fix `allowCredentials` / `excludeCredentials` option ([#266](https://github.com/atinux/nuxt-auth-utils/pull/266))

### 🏡 Chore

- **release:** V0.5.0 ([404acc6](https://github.com/atinux/nuxt-auth-utils/commit/404acc6))
- Update deps ([8947e40](https://github.com/atinux/nuxt-auth-utils/commit/8947e40))

### ❤️ Contributors

- Sébastien Chopin ([@atinux](http://github.com/atinux))
- Gerben Mulder <[email protected]>

## v0.5.0

[compare changes](https://github.com/atinux/nuxt-auth-utils/compare/v0.4.4...v0.5.0)
Expand Down
90 changes: 85 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ Add Authentication to Nuxt applications with secured & sealed cookies sessions.
## Features

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

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.

Expand Down Expand Up @@ -204,7 +205,10 @@ It can also be set using environment variables:
#### Supported OAuth Providers

- Apple
- Atlassian
- Auth0
- Authentik
- AWS Cognito
- Battle.net
- Discord
Expand All @@ -213,21 +217,27 @@ It can also be set using environment variables:
- GitHub
- GitLab
- Google
- Hubspot
- Instagram
- Keycloak
- Line
- Linear
- LinkedIn
- Microsoft
- PayPal
- Polar
- Seznam
- Spotify
- Steam
- Strava
- TikTok
- Twitch
- VK
- WorkOS
- X (Twitter)
- XSUAA
- Yandex
- Zitadel

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

Expand Down Expand Up @@ -348,10 +358,21 @@ The following code does not include the actual database queries, but shows the g
import { z } from 'zod'
export default defineWebAuthnRegisterEventHandler({
// optional
validateUser: z.object({
// we want the userName to be a valid email
userName: z.string().email()
}).parse,
async validateUser(userBody, event) {
// bonus: check if the user is already authenticated to link a credential to his account
// We first check if the user is already authenticated by getting the session
// And verify that the email is the same as the one in session
const session = await getUserSession(event)
if (session.user?.email && session.user.email !== body.userName) {
throw createError({ statusCode: 400, message: 'Email not matching curent session' })
}

// If he registers a new account with credentials
return z.object({
// we want the userName to be a valid email
userName: z.string().email()
}).parse(userBody)
},
async onSuccess(event, { credential, user }) {
// The credential creation has been successful
// We need to create a user if it does not exist
Expand Down Expand Up @@ -593,6 +614,65 @@ You can use the `placeholder` slot to show a placeholder on server-side and whil

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.

## WebSocket Support

Nuxt Auth Utils is compatible with [Nitro WebSockets](https://nitro.build/guide/websocket).

Make sure to enable the `experimental.websocket` option in your `nuxt.config.ts`:

```ts
export default defineNuxtConfig({
nitro: {
experimental: {
websocket: true
}
}
})
```

You can use the `requireUserSession` function in the `upgrade` function to check if the user is authenticated before upgrading the WebSocket connection.

```ts
// server/routes/ws.ts
export default defineWebSocketHandler({
async upgrade(request) {
// Make sure the user is authenticated before upgrading the WebSocket connection
await requireUserSession(request)
},
async open(peer) {
const { user } = await requireUserSession(peer)

peer.send(`Hello, ${user.name}!`)
},
message(peer, message) {
peer.send(`Echo: ${message}`)
},
})
```

Then, in your application, you can use the [useWebSocket](https://vueuse.org/core/useWebSocket/) composable to connect to the WebSocket:

```vue
<script setup>
const { status, data, send, open, close } = useWebSocket('/ws', { immediate: false })
// Only open the websocket after the page is hydrated (client-only)
onMounted(open)
</script>
<template>
<div>
<p>Status: {{ status }}</p>
<p>Data: {{ data }}</p>
<p>
<button @click="open">Open</button>
<button @click="close(1000, 'Closing')">Close</button>
<button @click="send('hello')">Send hello</button>
</p>
</div>
</template>
```

## Configuration

### Session Storage
Expand Down
Loading

0 comments on commit 7a30d6b

Please sign in to comment.