Skip to content

Commit

Permalink
Merge branch 'Atinux:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Azurency committed Jan 10, 2024
2 parents 6cd7498 + 1d0d0cc commit 68ec7de
Show file tree
Hide file tree
Showing 16 changed files with 1,960 additions and 608 deletions.
2 changes: 2 additions & 0 deletions .nuxtrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# enable TypeScript bundler module resolution - https://www.typescriptlang.org/docs/handbook/modules/reference.html#bundler
experimental.typescriptBundlerResolution=true
55 changes: 55 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,61 @@
# Changelog


## v0.0.14

[compare changes](https://github.com/Atinux/nuxt-auth-utils/compare/v0.0.13...v0.0.14)

### 🚀 Enhancements

- Added keycloak as oauth provider ([#23](https://github.com/Atinux/nuxt-auth-utils/pull/23))

### 🏡 Chore

- Test bundler module resolution ([#32](https://github.com/Atinux/nuxt-auth-utils/pull/32))
- Update deps ([9d6b258](https://github.com/Atinux/nuxt-auth-utils/commit/9d6b258))

### ❤️ Contributors

- Sébastien Chopin ([@Atinux](http://github.com/Atinux))
- Yue JIN
- Daniel Roe <daniel@roe.dev>

## v0.0.13

[compare changes](https://github.com/Atinux/nuxt-auth-utils/compare/v0.0.12...v0.0.13)

### 🏡 Chore

- Rename session from verify to fetch ([10694e9](https://github.com/Atinux/nuxt-auth-utils/commit/10694e9))

### ❤️ Contributors

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

## v0.0.12

[compare changes](https://github.com/Atinux/nuxt-auth-utils/compare/v0.0.11...v0.0.12)

### 🩹 Fixes

- Correct arguments for hooks ([6e0193e](https://github.com/Atinux/nuxt-auth-utils/commit/6e0193e))

### ❤️ Contributors

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

## v0.0.11

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

### 🚀 Enhancements

- Add sessionHooks to extend user sessions ([c470319](https://github.com/Atinux/nuxt-auth-utils/commit/c470319))

### ❤️ Contributors

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

## v0.0.10

[compare changes](https://github.com/Atinux/nuxt-auth-utils/compare/v0.0.9...v0.0.10)
Expand Down
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ It can also be set using environment variables:
- Discord
- GitHub
- Google
- Keycloak
- LinkedIn
- Microsoft
- Spotify
Expand Down Expand Up @@ -188,6 +189,28 @@ export default oauth.githubEventHandler({

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

### Extend Session

We leverage hooks to let you extend the session data with your own data or to log when the user clear its session.

```ts
// server/plugins/session.ts
export default defineNitroPlugin(() => {
// Called when the session is fetched during SSR for the Vue composable (/api/_auth/session)
// Or when we call useUserSession().fetch()
sessionHooks.hook('fetch', async (session, event) => {
// extend User Session by calling your database
// or
// throw createError({ ... }) if session is invalid for example
})

// Called when we call useServerSession().clear() or clearUserSession(event)
sessionHooks.hook('clear', async (session, event) => {
// Log that user logged out
})
})
```

## Development

```bash
Expand Down
27 changes: 14 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nuxt-auth-utils",
"version": "0.0.10",
"version": "0.0.14",
"description": "Minimalist Auth module for Nuxt with SSR",
"repository": "Atinux/nuxt-auth-utils",
"license": "MIT",
Expand Down Expand Up @@ -30,26 +30,27 @@
"test:watch": "vitest watch"
},
"dependencies": {
"@nuxt/kit": "^3.8.2",
"@nuxt/kit": "^3.9.0",
"defu": "^6.1.3",
"hookable": "^5.5.3",
"ofetch": "^1.3.3",
"ohash": "^1.1.3"
},
"devDependencies": {
"@iconify-json/simple-icons": "^1.1.82",
"@iconify-json/simple-icons": "^1.1.86",
"@nuxt/devtools": "latest",
"@nuxt/eslint-config": "^0.2.0",
"@nuxt/module-builder": "^0.5.4",
"@nuxt/schema": "^3.8.2",
"@nuxt/test-utils": "^3.8.1",
"@nuxt/ui": "^2.11.0",
"@nuxt/ui-pro": "^0.5.0",
"@types/node": "^20.10.4",
"@nuxt/module-builder": "^0.5.5",
"@nuxt/schema": "^3.9.0",
"@nuxt/test-utils": "^3.9.0",
"@nuxt/ui": "^2.11.1",
"@nuxt/ui-pro": "^0.6.1",
"@types/node": "^20.10.6",
"changelogen": "^0.5.5",
"eslint": "^8.55.0",
"nuxt": "^3.8.2",
"eslint": "^8.56.0",
"nuxt": "^3.9.0",
"typescript": "^5.3.3",
"vitest": "^1.0.2",
"vue-tsc": "^1.8.25"
"vitest": "^1.1.3",
"vue-tsc": "^1.8.27"
}
}
5 changes: 5 additions & 0 deletions playground/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ NUXT_OAUTH_DISCORD_CLIENT_SECRET=
# Battle.net OAuth
NUXT_OAUTH_BATTLEDOTNET_CLIENT_ID=
NUXT_OAUTH_BATTLEDOTNET_CLIENT_SECRET=
# Keycloak OAuth
NUXT_OAUTH_KEYCLOAK_CLIENT_ID=
NUXT_OAUTH_KEYCLOAK_CLIENT_SECRET=
NUXT_OAUTH_KEYCLOAK_SERVER_URL=
NUXT_OAUTH_KEYCLOAK_REALM=
# LinkedIn
NUXT_OAUTH_LINKEDIN_CLIENT_ID=
NUXT_OAUTH_LINKEDIN_CLIENT_SECRET=
7 changes: 6 additions & 1 deletion playground/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,18 @@ const providers = computed(() => [
disabled: Boolean(user.value?.microsoft),
icon: 'i-simple-icons-microsoft',
},
{
label: user.value?.keycloak?.preferred_username || 'Keycloak',
to: '/auth/keycloak',
disabled: Boolean(user.value?.keycloak),
icon: 'i-simple-icons-redhat'
},
{
label: user.value?.linkedin?.email || 'LinkedIn',
to: '/auth/linkedin',
disabled: Boolean(user.value?.linkedin),
icon: 'i-simple-icons-linkedin',
}
].map(p => ({
...p,
prefetch: false,
Expand Down
2 changes: 2 additions & 0 deletions playground/auth.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ declare module '#auth-utils' {
microsoft?: any;
discord?: any
battledotnet?: any
keycloak?: any
linkedin?: any
}
extended?: any
loggedInAt: number
}
}
Expand Down
4 changes: 2 additions & 2 deletions playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"generate": "nuxi generate"
},
"dependencies": {
"nuxt": "3.8.1",
"nuxt": "^3.9.0",
"nuxt-auth-utils": "latest",
"vue": "3.3.8"
"vue": "^3.4.5"
}
}
15 changes: 15 additions & 0 deletions playground/server/plugins/session.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export default defineNitroPlugin(() => {
sessionHooks.hook('fetch', async (session) => {
// Extend User Session
// Or throw createError({ ... }) if session is invalid
session.extended = {
fromHooks: true
}
})

sessionHooks.hook('clear', async (session) => {

Check warning on line 10 in playground/server/plugins/session.ts

View workflow job for this annotation

GitHub Actions / lint

'session' is defined but never used
// Log that user logged out
console.log('User logged out')
})
})

12 changes: 12 additions & 0 deletions playground/server/routes/auth/keycloak.get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default oauth.keycloakEventHandler({
async onSuccess(event, { user }) {
await setUserSession(event, {
user: {
keycloak: user,
},
loggedInAt: Date.now(),
})

return sendRedirect(event, '/')
},
})
Loading

0 comments on commit 68ec7de

Please sign in to comment.