@linabase/js 0.2.2 → 0.2.3
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/index.cjs +16 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +16 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -631,13 +631,28 @@ var AuthClient = class {
|
|
|
631
631
|
/**
|
|
632
632
|
* Set (or clear) the current session. Use this to restore a persisted
|
|
633
633
|
* session on app launch (e.g., from AsyncStorage / SecureStore).
|
|
634
|
+
* Automatically refreshes the token if it has expired.
|
|
634
635
|
* Emits INITIAL_SESSION to onAuthStateChange listeners when called externally.
|
|
635
636
|
* Internal callers (signIn, signUp, etc.) pass _internal=true to skip the emit.
|
|
636
637
|
*/
|
|
637
638
|
setSession(session, _internal) {
|
|
638
639
|
this.currentSession = session;
|
|
639
640
|
if (this.onSessionChange) this.onSessionChange(session);
|
|
640
|
-
if (!_internal)
|
|
641
|
+
if (!_internal) {
|
|
642
|
+
if (session && session.expires_at <= Math.floor(Date.now() / 1e3)) {
|
|
643
|
+
this.refreshSession().then(({ error }) => {
|
|
644
|
+
if (error) {
|
|
645
|
+
this.currentSession = null;
|
|
646
|
+
if (this.onSessionChange) this.onSessionChange(null);
|
|
647
|
+
this.emit("SIGNED_OUT", null);
|
|
648
|
+
} else {
|
|
649
|
+
this.emit("INITIAL_SESSION", this.currentSession);
|
|
650
|
+
}
|
|
651
|
+
});
|
|
652
|
+
} else {
|
|
653
|
+
this.emit("INITIAL_SESSION", session);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
641
656
|
}
|
|
642
657
|
// ─── Email/Password ────────────────────────────────────────
|
|
643
658
|
async signUp(params) {
|
package/dist/index.d.cts
CHANGED
|
@@ -236,6 +236,7 @@ declare class AuthClient {
|
|
|
236
236
|
/**
|
|
237
237
|
* Set (or clear) the current session. Use this to restore a persisted
|
|
238
238
|
* session on app launch (e.g., from AsyncStorage / SecureStore).
|
|
239
|
+
* Automatically refreshes the token if it has expired.
|
|
239
240
|
* Emits INITIAL_SESSION to onAuthStateChange listeners when called externally.
|
|
240
241
|
* Internal callers (signIn, signUp, etc.) pass _internal=true to skip the emit.
|
|
241
242
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -236,6 +236,7 @@ declare class AuthClient {
|
|
|
236
236
|
/**
|
|
237
237
|
* Set (or clear) the current session. Use this to restore a persisted
|
|
238
238
|
* session on app launch (e.g., from AsyncStorage / SecureStore).
|
|
239
|
+
* Automatically refreshes the token if it has expired.
|
|
239
240
|
* Emits INITIAL_SESSION to onAuthStateChange listeners when called externally.
|
|
240
241
|
* Internal callers (signIn, signUp, etc.) pass _internal=true to skip the emit.
|
|
241
242
|
*/
|
package/dist/index.js
CHANGED
|
@@ -599,13 +599,28 @@ var AuthClient = class {
|
|
|
599
599
|
/**
|
|
600
600
|
* Set (or clear) the current session. Use this to restore a persisted
|
|
601
601
|
* session on app launch (e.g., from AsyncStorage / SecureStore).
|
|
602
|
+
* Automatically refreshes the token if it has expired.
|
|
602
603
|
* Emits INITIAL_SESSION to onAuthStateChange listeners when called externally.
|
|
603
604
|
* Internal callers (signIn, signUp, etc.) pass _internal=true to skip the emit.
|
|
604
605
|
*/
|
|
605
606
|
setSession(session, _internal) {
|
|
606
607
|
this.currentSession = session;
|
|
607
608
|
if (this.onSessionChange) this.onSessionChange(session);
|
|
608
|
-
if (!_internal)
|
|
609
|
+
if (!_internal) {
|
|
610
|
+
if (session && session.expires_at <= Math.floor(Date.now() / 1e3)) {
|
|
611
|
+
this.refreshSession().then(({ error }) => {
|
|
612
|
+
if (error) {
|
|
613
|
+
this.currentSession = null;
|
|
614
|
+
if (this.onSessionChange) this.onSessionChange(null);
|
|
615
|
+
this.emit("SIGNED_OUT", null);
|
|
616
|
+
} else {
|
|
617
|
+
this.emit("INITIAL_SESSION", this.currentSession);
|
|
618
|
+
}
|
|
619
|
+
});
|
|
620
|
+
} else {
|
|
621
|
+
this.emit("INITIAL_SESSION", session);
|
|
622
|
+
}
|
|
623
|
+
}
|
|
609
624
|
}
|
|
610
625
|
// ─── Email/Password ────────────────────────────────────────
|
|
611
626
|
async signUp(params) {
|