Skip to content

Commit 68ec7de

Browse files
authored
Merge branch 'Atinux:main' into main
2 parents 6cd7498 + 1d0d0cc commit 68ec7de

File tree

16 files changed

+1960
-608
lines changed

16 files changed

+1960
-608
lines changed

.nuxtrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# enable TypeScript bundler module resolution - https://www.typescriptlang.org/docs/handbook/modules/reference.html#bundler
2+
experimental.typescriptBundlerResolution=true

CHANGELOG.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,61 @@
11
# Changelog
22

33

4+
## v0.0.14
5+
6+
[compare changes](https://github.com/Atinux/nuxt-auth-utils/compare/v0.0.13...v0.0.14)
7+
8+
### 🚀 Enhancements
9+
10+
- Added keycloak as oauth provider ([#23](https://github.com/Atinux/nuxt-auth-utils/pull/23))
11+
12+
### 🏡 Chore
13+
14+
- Test bundler module resolution ([#32](https://github.com/Atinux/nuxt-auth-utils/pull/32))
15+
- Update deps ([9d6b258](https://github.com/Atinux/nuxt-auth-utils/commit/9d6b258))
16+
17+
### ❤️ Contributors
18+
19+
- Sébastien Chopin ([@Atinux](http://github.com/Atinux))
20+
- Yue JIN
21+
- Daniel Roe <[email protected]>
22+
23+
## v0.0.13
24+
25+
[compare changes](https://github.com/Atinux/nuxt-auth-utils/compare/v0.0.12...v0.0.13)
26+
27+
### 🏡 Chore
28+
29+
- Rename session from verify to fetch ([10694e9](https://github.com/Atinux/nuxt-auth-utils/commit/10694e9))
30+
31+
### ❤️ Contributors
32+
33+
- Sébastien Chopin ([@Atinux](http://github.com/Atinux))
34+
35+
## v0.0.12
36+
37+
[compare changes](https://github.com/Atinux/nuxt-auth-utils/compare/v0.0.11...v0.0.12)
38+
39+
### 🩹 Fixes
40+
41+
- Correct arguments for hooks ([6e0193e](https://github.com/Atinux/nuxt-auth-utils/commit/6e0193e))
42+
43+
### ❤️ Contributors
44+
45+
- Sébastien Chopin ([@Atinux](http://github.com/Atinux))
46+
47+
## v0.0.11
48+
49+
[compare changes](https://github.com/Atinux/nuxt-auth-utils/compare/v0.0.10...v0.0.11)
50+
51+
### 🚀 Enhancements
52+
53+
- Add sessionHooks to extend user sessions ([c470319](https://github.com/Atinux/nuxt-auth-utils/commit/c470319))
54+
55+
### ❤️ Contributors
56+
57+
- Sébastien Chopin ([@Atinux](http://github.com/Atinux))
58+
459
## v0.0.10
560

661
[compare changes](https://github.com/Atinux/nuxt-auth-utils/compare/v0.0.9...v0.0.10)

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ It can also be set using environment variables:
154154
- Discord
155155
- GitHub
156156
- Google
157+
- Keycloak
157158
- LinkedIn
158159
- Microsoft
159160
- Spotify
@@ -188,6 +189,28 @@ export default oauth.githubEventHandler({
188189

189190
Make sure to set the callback URL in your OAuth app settings as `<your-domain>/auth/github`.
190191

192+
### Extend Session
193+
194+
We leverage hooks to let you extend the session data with your own data or to log when the user clear its session.
195+
196+
```ts
197+
// server/plugins/session.ts
198+
export default defineNitroPlugin(() => {
199+
// Called when the session is fetched during SSR for the Vue composable (/api/_auth/session)
200+
// Or when we call useUserSession().fetch()
201+
sessionHooks.hook('fetch', async (session, event) => {
202+
// extend User Session by calling your database
203+
// or
204+
// throw createError({ ... }) if session is invalid for example
205+
})
206+
207+
// Called when we call useServerSession().clear() or clearUserSession(event)
208+
sessionHooks.hook('clear', async (session, event) => {
209+
// Log that user logged out
210+
})
211+
})
212+
```
213+
191214
## Development
192215

193216
```bash

package.json

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nuxt-auth-utils",
3-
"version": "0.0.10",
3+
"version": "0.0.14",
44
"description": "Minimalist Auth module for Nuxt with SSR",
55
"repository": "Atinux/nuxt-auth-utils",
66
"license": "MIT",
@@ -30,26 +30,27 @@
3030
"test:watch": "vitest watch"
3131
},
3232
"dependencies": {
33-
"@nuxt/kit": "^3.8.2",
33+
"@nuxt/kit": "^3.9.0",
3434
"defu": "^6.1.3",
35+
"hookable": "^5.5.3",
3536
"ofetch": "^1.3.3",
3637
"ohash": "^1.1.3"
3738
},
3839
"devDependencies": {
39-
"@iconify-json/simple-icons": "^1.1.82",
40+
"@iconify-json/simple-icons": "^1.1.86",
4041
"@nuxt/devtools": "latest",
4142
"@nuxt/eslint-config": "^0.2.0",
42-
"@nuxt/module-builder": "^0.5.4",
43-
"@nuxt/schema": "^3.8.2",
44-
"@nuxt/test-utils": "^3.8.1",
45-
"@nuxt/ui": "^2.11.0",
46-
"@nuxt/ui-pro": "^0.5.0",
47-
"@types/node": "^20.10.4",
43+
"@nuxt/module-builder": "^0.5.5",
44+
"@nuxt/schema": "^3.9.0",
45+
"@nuxt/test-utils": "^3.9.0",
46+
"@nuxt/ui": "^2.11.1",
47+
"@nuxt/ui-pro": "^0.6.1",
48+
"@types/node": "^20.10.6",
4849
"changelogen": "^0.5.5",
49-
"eslint": "^8.55.0",
50-
"nuxt": "^3.8.2",
50+
"eslint": "^8.56.0",
51+
"nuxt": "^3.9.0",
5152
"typescript": "^5.3.3",
52-
"vitest": "^1.0.2",
53-
"vue-tsc": "^1.8.25"
53+
"vitest": "^1.1.3",
54+
"vue-tsc": "^1.8.27"
5455
}
5556
}

playground/.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ NUXT_OAUTH_DISCORD_CLIENT_SECRET=
2525
# Battle.net OAuth
2626
NUXT_OAUTH_BATTLEDOTNET_CLIENT_ID=
2727
NUXT_OAUTH_BATTLEDOTNET_CLIENT_SECRET=
28+
# Keycloak OAuth
29+
NUXT_OAUTH_KEYCLOAK_CLIENT_ID=
30+
NUXT_OAUTH_KEYCLOAK_CLIENT_SECRET=
31+
NUXT_OAUTH_KEYCLOAK_SERVER_URL=
32+
NUXT_OAUTH_KEYCLOAK_REALM=
2833
# LinkedIn
2934
NUXT_OAUTH_LINKEDIN_CLIENT_ID=
3035
NUXT_OAUTH_LINKEDIN_CLIENT_SECRET=

playground/app.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,18 @@ const providers = computed(() => [
5050
disabled: Boolean(user.value?.microsoft),
5151
icon: 'i-simple-icons-microsoft',
5252
},
53+
{
54+
label: user.value?.keycloak?.preferred_username || 'Keycloak',
55+
to: '/auth/keycloak',
56+
disabled: Boolean(user.value?.keycloak),
57+
icon: 'i-simple-icons-redhat'
58+
},
5359
{
5460
label: user.value?.linkedin?.email || 'LinkedIn',
5561
to: '/auth/linkedin',
5662
disabled: Boolean(user.value?.linkedin),
5763
icon: 'i-simple-icons-linkedin',
5864
}
59-
6065
].map(p => ({
6166
...p,
6267
prefetch: false,

playground/auth.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ declare module '#auth-utils' {
99
microsoft?: any;
1010
discord?: any
1111
battledotnet?: any
12+
keycloak?: any
1213
linkedin?: any
1314
}
15+
extended?: any
1416
loggedInAt: number
1517
}
1618
}

playground/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
"generate": "nuxi generate"
99
},
1010
"dependencies": {
11-
"nuxt": "3.8.1",
11+
"nuxt": "^3.9.0",
1212
"nuxt-auth-utils": "latest",
13-
"vue": "3.3.8"
13+
"vue": "^3.4.5"
1414
}
1515
}

playground/server/plugins/session.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export default defineNitroPlugin(() => {
2+
sessionHooks.hook('fetch', async (session) => {
3+
// Extend User Session
4+
// Or throw createError({ ... }) if session is invalid
5+
session.extended = {
6+
fromHooks: true
7+
}
8+
})
9+
10+
sessionHooks.hook('clear', async (session) => {
11+
// Log that user logged out
12+
console.log('User logged out')
13+
})
14+
})
15+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export default oauth.keycloakEventHandler({
2+
async onSuccess(event, { user }) {
3+
await setUserSession(event, {
4+
user: {
5+
keycloak: user,
6+
},
7+
loggedInAt: Date.now(),
8+
})
9+
10+
return sendRedirect(event, '/')
11+
},
12+
})

0 commit comments

Comments
 (0)