diff --git a/package.json b/package.json index 91d4b588..8834487c 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", @@ -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" @@ -70,7 +70,7 @@ }, "resolutions": { "@nuxt/kit": "^4.0.0", - "@nuxtjs/hanko": "link:." + "@nullix/nuxtjs-hanko": "link:." }, "packageManager": "pnpm@10.26.2" } diff --git a/playground/pages/login.vue b/playground/pages/login.vue index 55ce65e0..7e4535bd 100644 --- a/playground/pages/login.vue +++ b/playground/pages/login.vue @@ -8,10 +8,13 @@ definePageMeta({

Log in

- Only logged out users can see this page

definePageMeta({
-  middleware: ['hanko-logged-out'],
-})
+ Only logged out users can see this page

+

+    definePageMeta({
+      middleware: ['hanko-logged-out'],
+    })
+      

You were redirected here from {{ $route.query.redirect }}, once you login, you'll be sent back automatically!

diff --git a/playground/pages/protected.vue b/playground/pages/protected.vue index 11a81886..37191e42 100644 --- a/playground/pages/protected.vue +++ b/playground/pages/protected.vue @@ -12,10 +12,13 @@ function logout() {

Protected Page

- Only logged in users can see this page

definePageMeta({
-  middleware: ['hanko-logged-in'],
-})
+ Only logged in users can see this page

+

+    definePageMeta({
+      middleware: ['hanko-logged-in'],
+    })
+      
diff --git a/playground/pages/user.vue b/playground/pages/user.vue index d1739f53..33740e91 100644 --- a/playground/pages/user.vue +++ b/playground/pages/user.vue @@ -20,10 +20,13 @@ async function tryAuthenticatedRequest() {

You are logged in!

- Only logged in users can see this page

definePageMeta({
-  middleware: ['hanko-logged-in'],
-})
+ Only logged in users can see this page

+

+    definePageMeta({
+      middleware: ['hanko-logged-in'],
+    })
+      
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 221f0e8b..179a3129 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -16,8 +16,8 @@ importers: specifier: ^4.0.0 version: 4.2.2(magicast@0.5.1) '@teamhanko/hanko-elements': - specifier: 1.5.2 - version: 1.5.2 + specifier: 2.3.0 + version: 2.3.0 defu: specifier: ^6.1.4 version: 6.1.4 @@ -1406,11 +1406,11 @@ packages: peerDependencies: eslint: '>=9.0.0' - '@teamhanko/hanko-elements@1.5.2': - resolution: {integrity: sha512-RrOgSoKwHbysDOOffOHn3p8s/zXxY2qvWwZFQdMeEP8Qp/C/RQBwGOzax0Y2gySWflDHM2uu4+tW8dXB+mZfQg==} + '@teamhanko/hanko-elements@2.3.0': + resolution: {integrity: sha512-hMDecxL4gNNxk8mOwWxqaRvguSNPZ9QPrUVcjFP6kwZN3wHj47iD4A+htWFB+VKLWAqyDiioyx/MAM4HhPMsAQ==} - '@teamhanko/hanko-frontend-sdk@1.5.2': - resolution: {integrity: sha512-sSY2NGsJRndrC4HwxBIdog9gOGUzJ3EGKmEn7p+rzXzJaLik3ywJb25DloegPekMZQ8hwOzliF0uJh7kNxFgTA==} + '@teamhanko/hanko-frontend-sdk@2.3.0': + resolution: {integrity: sha512-rZkyWddmozkgpsC0mN+1FuxG2L7OCYsD3D040Njp1o73VyZFpvZ1rbBQv7eOI3V7qZc4rtgKc+fPizM1Hp2pCQ==} '@teamhanko/preact-custom-element@4.2.2': resolution: {integrity: sha512-3djCQr25IxQIgpidxD8J0fTQ7/hMuoa5Nmv7delQc6sX4kXgv9e/pE01cywpmGZLi69H1KUH4dmZ4cPPJQrsQQ==} @@ -5663,15 +5663,15 @@ snapshots: estraverse: 5.3.0 picomatch: 4.0.3 - '@teamhanko/hanko-elements@1.5.2': + '@teamhanko/hanko-elements@2.3.0': dependencies: '@denysvuika/preact-translate': 0.5.1(preact@10.27.2) - '@teamhanko/hanko-frontend-sdk': 1.5.2 + '@teamhanko/hanko-frontend-sdk': 2.3.0 '@teamhanko/preact-custom-element': 4.2.2(preact@10.27.2) classnames: 2.5.1 preact: 10.27.2 - '@teamhanko/hanko-frontend-sdk@1.5.2': + '@teamhanko/hanko-frontend-sdk@2.3.0': dependencies: '@types/js-cookie': 3.0.6 diff --git a/src/module.ts b/src/module.ts index 87823a5d..d9f66bb8 100644 --- a/src/module.ts +++ b/src/module.ts @@ -28,6 +28,8 @@ export interface ModuleOptions { translations?: RegisterOptions['translations'] translationsLocation?: RegisterOptions['translationsLocation'] fallbackLanguage?: RegisterOptions['fallbackLanguage'] + sessionCheckInterval?: RegisterOptions['sessionCheckInterval'] + sessionTokenLocation?: RegisterOptions['sessionTokenLocation'] } } diff --git a/src/runtime/components.d.ts b/src/runtime/components.d.ts index f4ff11c7..69357f37 100644 --- a/src/runtime/components.d.ts +++ b/src/runtime/components.d.ts @@ -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 }> @@ -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> } diff --git a/src/runtime/composables/index.ts b/src/runtime/composables/index.ts index 5dae66cd..56b9a59e 100644 --- a/src/runtime/composables/index.ts +++ b/src/runtime/composables/index.ts @@ -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. @@ -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) } diff --git a/src/runtime/middleware/logged-in.ts b/src/runtime/middleware/logged-in.ts index bd79eed1..d40e5eb0 100644 --- a/src/runtime/middleware/logged-in.ts +++ b/src/runtime/middleware/logged-in.ts @@ -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 @@ -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 })) } diff --git a/src/runtime/middleware/logged-out.ts b/src/runtime/middleware/logged-out.ts index e569ca6e..fac59c54 100644 --- a/src/runtime/middleware/logged-out.ts +++ b/src/runtime/middleware/logged-out.ts @@ -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) }