@nuxtjs/better-auth 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxtjs/better-auth",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "configKey": "auth",
5
5
  "compatibility": {
6
6
  "nuxt": ">=4.0.0"
package/dist/module.mjs CHANGED
@@ -10,7 +10,7 @@ import { randomBytes } from 'node:crypto';
10
10
  import { isCI, isTest } from 'std-env';
11
11
  export { defineClientAuth, defineServerAuth } from '../dist/runtime/config.js';
12
12
 
13
- const version = "0.2.0";
13
+ const version = "0.2.2";
14
14
 
15
15
  const CONFIG_EXTENSIONS = [".ts", ".js"];
16
16
  const CONFIG_EXTENSION_RE = /\.(?:ts|js)$/;
@@ -87,8 +87,21 @@ export function useUserSession() {
87
87
  throw error;
88
88
  }
89
89
  }
90
+ function queueHydrationReconciliation() {
91
+ if (hydrationReconcileQueued.value)
92
+ return;
93
+ hydrationReconcileQueued.value = true;
94
+ nuxtApp.hook("app:mounted", async () => {
95
+ await fetchSession({ force: true });
96
+ hydrationReconcileQueued.value = false;
97
+ });
98
+ }
90
99
  if (runtimeFlags.client && rawClient) {
91
100
  const clientSession = rawClient.useSession();
101
+ const initialClientSession = clientSession.value;
102
+ const shouldReconcileInitialHydration = nuxtApp.isHydrating && nuxtApp.payload.serverRendered && Boolean(session.value && user.value) && !initialClientSession?.data?.session && !initialClientSession?.data?.user && !initialClientSession?.isPending && !initialClientSession?.isRefetching;
103
+ if (shouldReconcileInitialHydration)
104
+ queueHydrationReconciliation();
92
105
  watch(
93
106
  () => clientSession.value,
94
107
  (newSession) => {
@@ -101,21 +114,14 @@ export function useUserSession() {
101
114
  } else if (!newSession?.isPending && !newSession?.isRefetching) {
102
115
  const isHydrationEmptySnapshot = nuxtApp.isHydrating && nuxtApp.payload.serverRendered && Boolean(session.value && user.value) && !newSession?.data?.session && !newSession?.data?.user;
103
116
  if (isHydrationEmptySnapshot) {
104
- if (!hydrationReconcileQueued.value) {
105
- hydrationReconcileQueued.value = true;
106
- nuxtApp.hook("app:mounted", async () => {
107
- await fetchSession({ force: true });
108
- hydrationReconcileQueued.value = false;
109
- });
110
- }
117
+ queueHydrationReconciliation();
111
118
  return;
112
119
  }
113
120
  clearSession();
114
121
  }
115
122
  if (!authReady.value && !newSession?.isPending && !newSession?.isRefetching)
116
123
  authReady.value = true;
117
- },
118
- { immediate: true, deep: true }
124
+ }
119
125
  );
120
126
  }
121
127
  function waitForSession() {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nuxtjs/better-auth",
3
3
  "type": "module",
4
- "version": "0.2.0",
4
+ "version": "0.2.2",
5
5
  "description": "Nuxt module for Better Auth integration with NuxtHub, route protection, session management, and role-based access",
6
6
  "author": "onmax",
7
7
  "license": "MIT",