Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@nuxtjs/hanko",
"version": "1.0.0",
"description": "Hanko integration for Nuxt",
"name": "@nullix/nuxtjs-hanko",
"version": "2.0.0",
"description": "Hanko V2 integration for Nuxt By Harm-Nullix",
"keywords": [
"authentication",
"webauthn",
Expand All @@ -13,7 +13,7 @@
],
"repository": {
"type": "git",
"url": "git+https://github.com/nuxt-modules/hanko.git"
"url": "git+https://github.com/Harm-Nullix/nuxt-hanko.git"
},
"license": "MIT",
"type": "module",
Expand Down Expand Up @@ -49,7 +49,7 @@
},
"dependencies": {
"@nuxt/kit": "^4.0.0",
"@teamhanko/hanko-elements": "1.5.2",
"@teamhanko/hanko-elements": "2.3.0",
"defu": "^6.1.4",
"jose": "^6.0.0",
"ufo": "^1.5.4"
Expand All @@ -70,7 +70,7 @@
},
"resolutions": {
"@nuxt/kit": "^4.0.0",
"@nuxtjs/hanko": "link:."
"@nullix/nuxtjs-hanko": "link:."
},
"packageManager": "pnpm@10.26.2"
}
9 changes: 6 additions & 3 deletions playground/pages/login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ definePageMeta({
<main>
<h1>Log in</h1>
<p>
Only logged out users can see this page<pre>definePageMeta({
middleware: ['hanko-logged-out'],
})</pre>
Only logged out users can see this page
</p>
<pre><code>
definePageMeta({
middleware: ['hanko-logged-out'],
})
</code></pre>
<p v-if="$route.query.redirect">
You were redirected here from {{ $route.query.redirect }}, once you login, you'll be sent back automatically!
</p>
Expand Down
9 changes: 6 additions & 3 deletions playground/pages/protected.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ function logout() {
<div>
<h1>Protected Page</h1>
<p>
Only logged in users can see this page<pre>definePageMeta({
middleware: ['hanko-logged-in'],
})</pre>
Only logged in users can see this page
</p>
<pre><code>
definePageMeta({
middleware: ['hanko-logged-in'],
})
</code></pre>
<button @click="logout">
Log me out
</button>
Expand Down
9 changes: 6 additions & 3 deletions playground/pages/user.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ async function tryAuthenticatedRequest() {
<main>
<h1>You are logged in!</h1>
<p>
Only logged in users can see this page<pre>definePageMeta({
middleware: ['hanko-logged-in'],
})</pre>
Only logged in users can see this page
</p>
<pre><code>
definePageMeta({
middleware: ['hanko-logged-in'],
})
</code></pre>
<button @click="logout">
Log me out
</button>
Expand Down
18 changes: 9 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export interface ModuleOptions {
translations?: RegisterOptions['translations']
translationsLocation?: RegisterOptions['translationsLocation']
fallbackLanguage?: RegisterOptions['fallbackLanguage']
sessionCheckInterval?: RegisterOptions['sessionCheckInterval']
sessionTokenLocation?: RegisterOptions['sessionTokenLocation']
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/runtime/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ declare module 'vue' {
* Currently supported values are "en" for English and "de" for German.
* If the value is omitted, "en" is used.
*/
lang?: 'en' | 'de' | (string & {})
lang?: 'bn' | 'de' | 'en' | 'fr' | 'it' | 'pt-BR' | 'zh' | (string & {})
/** A space-separated list of experimental features to be enabled. See experimental features. */
experimental?: string
}>
Expand All @@ -16,7 +16,7 @@ declare module 'vue' {
* Currently supported values are "en" for English and "de" for German.
* If the value is omitted, "en" is used.
*/
lang?: 'en' | 'de' | (string & {})
lang?: 'bn' | 'de' | 'en' | 'fr' | 'it' | 'pt-BR' | 'zh' | (string & {})
}>
HankoEvents: DefineComponent<Record<string, unknown>>
}
Expand Down
21 changes: 13 additions & 8 deletions src/runtime/composables/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Hanko } from '@teamhanko/hanko-elements'
import { useRuntimeConfig } from '#imports'
import { useRuntimeConfig, useState, toValue } from '#imports'

/**
* This composable returns a Hanko instance.
Expand All @@ -10,12 +10,17 @@ export function useHanko() {
if (import.meta.server) {
return null
}

const hankoConfig = useRuntimeConfig().public.hanko
return new Hanko(hankoConfig.apiURL, {
cookieName: hankoConfig.cookieName,
localStorageKey: hankoConfig.storageKey,
cookieSameSite: hankoConfig.cookieSameSite,
cookieDomain: hankoConfig.cookieDomain,
})

const hanko = useState(
'single-hanko-instance',
() =>
new Hanko(hankoConfig.apiURL, {
cookieName: hankoConfig.cookieName,
localStorageKey: hankoConfig.storageKey,
cookieSameSite: hankoConfig.cookieSameSite,
cookieDomain: hankoConfig.cookieDomain,
}),
)
return toValue(hanko)
}
3 changes: 1 addition & 2 deletions src/runtime/middleware/logged-in.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { withQuery } from 'ufo'
import { defineNuxtRouteMiddleware, navigateTo, useRouter, useAppConfig, useHanko, useRequestEvent } from '#imports'
import type {} from 'nuxt/app'

export default defineNuxtRouteMiddleware(async (to) => {
const redirects = useAppConfig().hanko.redirects
Expand All @@ -16,7 +15,7 @@ export default defineNuxtRouteMiddleware(async (to) => {

const hanko = useHanko()!

if (!(await hanko.user.getCurrent().catch(() => null)) && to.path !== redirects.login) {
if (!(await hanko.getUser().catch(() => null)) && to.path !== redirects.login) {
return navigateTo(withQuery(redirects.login, { redirect: to.path }))
}

Expand Down
2 changes: 1 addition & 1 deletion src/runtime/middleware/logged-out.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default defineNuxtRouteMiddleware(async (to) => {

const hanko = useHanko()!

if ((await hanko.user.getCurrent().catch(() => null)) && to.path !== redirects.home) {
if ((await hanko.getUser().catch(() => null)) && to.path !== redirects.home) {
return navigateTo(redirects.home)
}

Expand Down
Loading