@aurabase/auth 0.7.3 → 0.7.5
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 +33 -19
- package/dist/index.d.cts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +33 -19
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -810,6 +810,14 @@ var AuthService = class extends core.BaseService {
|
|
|
810
810
|
this._applyingRemote = false;
|
|
811
811
|
}
|
|
812
812
|
}
|
|
813
|
+
_isServiceRoleClient() {
|
|
814
|
+
return Boolean(this.client.apiKey?.startsWith("aura_sk_"));
|
|
815
|
+
}
|
|
816
|
+
_persistTokens(accessToken, refreshToken, user, event = "SIGNED_IN") {
|
|
817
|
+
if (this._isServiceRoleClient()) return;
|
|
818
|
+
this.client.authStore.save(accessToken, refreshToken, user);
|
|
819
|
+
this._emitEvent(event, user, accessToken);
|
|
820
|
+
}
|
|
813
821
|
/** Démonte le cycle de vie proactif : ticker, visibilité, BroadcastChannel, listeners. */
|
|
814
822
|
dispose() {
|
|
815
823
|
if (this._disposed) return;
|
|
@@ -948,8 +956,7 @@ var AuthService = class extends core.BaseService {
|
|
|
948
956
|
provider_token: tp.provider_token,
|
|
949
957
|
provider_refresh_token: tp.provider_refresh_token
|
|
950
958
|
};
|
|
951
|
-
this.
|
|
952
|
-
this._emitEvent("SIGNED_IN", tp.user, tp.access_token);
|
|
959
|
+
this._persistTokens(tp.access_token, tp.refresh_token, tp.user, "SIGNED_IN");
|
|
953
960
|
}
|
|
954
961
|
if (res.data && isMfaChallenge(res.data)) {
|
|
955
962
|
const mfa = res.data;
|
|
@@ -984,8 +991,7 @@ var AuthService = class extends core.BaseService {
|
|
|
984
991
|
provider_token: tp.provider_token,
|
|
985
992
|
provider_refresh_token: tp.provider_refresh_token
|
|
986
993
|
};
|
|
987
|
-
this.
|
|
988
|
-
this._emitEvent("SIGNED_IN", tp.user, tp.access_token);
|
|
994
|
+
this._persistTokens(tp.access_token, tp.refresh_token, tp.user, "SIGNED_IN");
|
|
989
995
|
}
|
|
990
996
|
if (res.data && isMfaChallenge(res.data)) {
|
|
991
997
|
const mfa = res.data;
|
|
@@ -1095,8 +1101,7 @@ var AuthService = class extends core.BaseService {
|
|
|
1095
1101
|
async signInAnonymously() {
|
|
1096
1102
|
const res = await this.request("POST", `${this.prefix}/anonymous`);
|
|
1097
1103
|
if (res.data) {
|
|
1098
|
-
this.
|
|
1099
|
-
this._emitEvent("SIGNED_IN", res.data.user, res.data.access_token);
|
|
1104
|
+
this._persistTokens(res.data.access_token, res.data.refresh_token, res.data.user, "SIGNED_IN");
|
|
1100
1105
|
}
|
|
1101
1106
|
return res;
|
|
1102
1107
|
}
|
|
@@ -1154,9 +1159,19 @@ var AuthService = class extends core.BaseService {
|
|
|
1154
1159
|
}
|
|
1155
1160
|
/**
|
|
1156
1161
|
* Installe une session à partir d'un jeton d'accès et d'un jeton de rafraîchissement existants (par exemple reçus d'un serveur).
|
|
1162
|
+
* Accepte indifféremment deux chaînes positionnelles `(accessToken, refreshToken)` ou un objet `{ access_token, refresh_token }` (parité DX Supabase).
|
|
1157
1163
|
* Un jeton d'accès expiré est rafraîchi ; une session invalide est refusée et l'état précédent est restauré.
|
|
1158
1164
|
*/
|
|
1159
|
-
async setSession(
|
|
1165
|
+
async setSession(tokenOrSession, possibleRefreshToken) {
|
|
1166
|
+
let accessToken;
|
|
1167
|
+
let refreshToken;
|
|
1168
|
+
if (typeof tokenOrSession === "object" && tokenOrSession !== null) {
|
|
1169
|
+
accessToken = tokenOrSession.access_token || "";
|
|
1170
|
+
refreshToken = tokenOrSession.refresh_token || "";
|
|
1171
|
+
} else {
|
|
1172
|
+
accessToken = tokenOrSession || "";
|
|
1173
|
+
refreshToken = possibleRefreshToken || "";
|
|
1174
|
+
}
|
|
1160
1175
|
const store = this.client.authStore;
|
|
1161
1176
|
const prev = { token: store.token, refreshToken: store.refreshToken, user: store.user };
|
|
1162
1177
|
const hadValidPrev = !!(prev.token && prev.refreshToken && prev.user && prev.user.id);
|
|
@@ -1234,8 +1249,7 @@ var AuthService = class extends core.BaseService {
|
|
|
1234
1249
|
}
|
|
1235
1250
|
if (res.data) {
|
|
1236
1251
|
const tp = res.data;
|
|
1237
|
-
this.
|
|
1238
|
-
this._emitEvent(successEvent, tp.user, tp.access_token);
|
|
1252
|
+
this._persistTokens(tp.access_token, tp.refresh_token, tp.user, successEvent);
|
|
1239
1253
|
}
|
|
1240
1254
|
return res;
|
|
1241
1255
|
} finally {
|
|
@@ -1643,8 +1657,7 @@ var AuthService = class extends core.BaseService {
|
|
|
1643
1657
|
credential: assertionToJson(cred)
|
|
1644
1658
|
});
|
|
1645
1659
|
if (res.data) {
|
|
1646
|
-
this.
|
|
1647
|
-
this._emitEvent("SIGNED_IN", res.data.user, res.data.access_token);
|
|
1660
|
+
this._persistTokens(res.data.access_token, res.data.refresh_token, res.data.user, "SIGNED_IN");
|
|
1648
1661
|
}
|
|
1649
1662
|
return res;
|
|
1650
1663
|
}
|
|
@@ -1695,8 +1708,7 @@ var AuthService = class extends core.BaseService {
|
|
|
1695
1708
|
provider_token: tp.provider_token,
|
|
1696
1709
|
provider_refresh_token: tp.provider_refresh_token
|
|
1697
1710
|
};
|
|
1698
|
-
this.
|
|
1699
|
-
this._emitEvent("SIGNED_IN", tp.user, tp.access_token);
|
|
1711
|
+
this._persistTokens(tp.access_token, tp.refresh_token, tp.user, "SIGNED_IN");
|
|
1700
1712
|
}
|
|
1701
1713
|
return res;
|
|
1702
1714
|
}
|
|
@@ -1766,8 +1778,7 @@ var AuthService = class extends core.BaseService {
|
|
|
1766
1778
|
async _verifyToTokenPair(path, body) {
|
|
1767
1779
|
const res = await this.request("POST", path, body);
|
|
1768
1780
|
if (res.data) {
|
|
1769
|
-
this.
|
|
1770
|
-
this._emitEvent("SIGNED_IN", res.data.user, res.data.access_token);
|
|
1781
|
+
this._persistTokens(res.data.access_token, res.data.refresh_token, res.data.user, "SIGNED_IN");
|
|
1771
1782
|
}
|
|
1772
1783
|
return res;
|
|
1773
1784
|
}
|
|
@@ -1840,8 +1851,7 @@ var AuthService = class extends core.BaseService {
|
|
|
1840
1851
|
}
|
|
1841
1852
|
if (res.data) {
|
|
1842
1853
|
const tp = res.data;
|
|
1843
|
-
this.
|
|
1844
|
-
this._emitEvent("SIGNED_IN", tp.user, tp.access_token);
|
|
1854
|
+
this._persistTokens(tp.access_token, tp.refresh_token, tp.user, "SIGNED_IN");
|
|
1845
1855
|
}
|
|
1846
1856
|
return res;
|
|
1847
1857
|
}
|
|
@@ -1875,8 +1885,12 @@ var AuthService = class extends core.BaseService {
|
|
|
1875
1885
|
credentials
|
|
1876
1886
|
);
|
|
1877
1887
|
if (res.data) {
|
|
1878
|
-
this.
|
|
1879
|
-
|
|
1888
|
+
this._persistTokens(
|
|
1889
|
+
res.data.access_token,
|
|
1890
|
+
res.data.refresh_token,
|
|
1891
|
+
res.data.user,
|
|
1892
|
+
"USER_UPDATED"
|
|
1893
|
+
);
|
|
1880
1894
|
}
|
|
1881
1895
|
return res;
|
|
1882
1896
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -303,6 +303,8 @@ declare class AuthService extends BaseService {
|
|
|
303
303
|
private _cleanAuthParamsFromUrl;
|
|
304
304
|
private _broadcastState;
|
|
305
305
|
private _applyRemoteState;
|
|
306
|
+
private _isServiceRoleClient;
|
|
307
|
+
private _persistTokens;
|
|
306
308
|
/** Démonte le cycle de vie proactif : ticker, visibilité, BroadcastChannel, listeners. */
|
|
307
309
|
dispose(): void;
|
|
308
310
|
/**
|
|
@@ -427,9 +429,13 @@ declare class AuthService extends BaseService {
|
|
|
427
429
|
}>;
|
|
428
430
|
/**
|
|
429
431
|
* Installe une session à partir d'un jeton d'accès et d'un jeton de rafraîchissement existants (par exemple reçus d'un serveur).
|
|
432
|
+
* Accepte indifféremment deux chaînes positionnelles `(accessToken, refreshToken)` ou un objet `{ access_token, refresh_token }` (parité DX Supabase).
|
|
430
433
|
* Un jeton d'accès expiré est rafraîchi ; une session invalide est refusée et l'état précédent est restauré.
|
|
431
434
|
*/
|
|
432
|
-
setSession(
|
|
435
|
+
setSession(tokenOrSession: string | {
|
|
436
|
+
access_token: string;
|
|
437
|
+
refresh_token: string;
|
|
438
|
+
}, possibleRefreshToken?: string): Promise<AuraResponse<User>>;
|
|
433
439
|
/**
|
|
434
440
|
* Échange le code d'autorisation PKCE contre une session.
|
|
435
441
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -303,6 +303,8 @@ declare class AuthService extends BaseService {
|
|
|
303
303
|
private _cleanAuthParamsFromUrl;
|
|
304
304
|
private _broadcastState;
|
|
305
305
|
private _applyRemoteState;
|
|
306
|
+
private _isServiceRoleClient;
|
|
307
|
+
private _persistTokens;
|
|
306
308
|
/** Démonte le cycle de vie proactif : ticker, visibilité, BroadcastChannel, listeners. */
|
|
307
309
|
dispose(): void;
|
|
308
310
|
/**
|
|
@@ -427,9 +429,13 @@ declare class AuthService extends BaseService {
|
|
|
427
429
|
}>;
|
|
428
430
|
/**
|
|
429
431
|
* Installe une session à partir d'un jeton d'accès et d'un jeton de rafraîchissement existants (par exemple reçus d'un serveur).
|
|
432
|
+
* Accepte indifféremment deux chaînes positionnelles `(accessToken, refreshToken)` ou un objet `{ access_token, refresh_token }` (parité DX Supabase).
|
|
430
433
|
* Un jeton d'accès expiré est rafraîchi ; une session invalide est refusée et l'état précédent est restauré.
|
|
431
434
|
*/
|
|
432
|
-
setSession(
|
|
435
|
+
setSession(tokenOrSession: string | {
|
|
436
|
+
access_token: string;
|
|
437
|
+
refresh_token: string;
|
|
438
|
+
}, possibleRefreshToken?: string): Promise<AuraResponse<User>>;
|
|
433
439
|
/**
|
|
434
440
|
* Échange le code d'autorisation PKCE contre une session.
|
|
435
441
|
*
|
package/dist/index.js
CHANGED
|
@@ -808,6 +808,14 @@ var AuthService = class extends BaseService {
|
|
|
808
808
|
this._applyingRemote = false;
|
|
809
809
|
}
|
|
810
810
|
}
|
|
811
|
+
_isServiceRoleClient() {
|
|
812
|
+
return Boolean(this.client.apiKey?.startsWith("aura_sk_"));
|
|
813
|
+
}
|
|
814
|
+
_persistTokens(accessToken, refreshToken, user, event = "SIGNED_IN") {
|
|
815
|
+
if (this._isServiceRoleClient()) return;
|
|
816
|
+
this.client.authStore.save(accessToken, refreshToken, user);
|
|
817
|
+
this._emitEvent(event, user, accessToken);
|
|
818
|
+
}
|
|
811
819
|
/** Démonte le cycle de vie proactif : ticker, visibilité, BroadcastChannel, listeners. */
|
|
812
820
|
dispose() {
|
|
813
821
|
if (this._disposed) return;
|
|
@@ -946,8 +954,7 @@ var AuthService = class extends BaseService {
|
|
|
946
954
|
provider_token: tp.provider_token,
|
|
947
955
|
provider_refresh_token: tp.provider_refresh_token
|
|
948
956
|
};
|
|
949
|
-
this.
|
|
950
|
-
this._emitEvent("SIGNED_IN", tp.user, tp.access_token);
|
|
957
|
+
this._persistTokens(tp.access_token, tp.refresh_token, tp.user, "SIGNED_IN");
|
|
951
958
|
}
|
|
952
959
|
if (res.data && isMfaChallenge(res.data)) {
|
|
953
960
|
const mfa = res.data;
|
|
@@ -982,8 +989,7 @@ var AuthService = class extends BaseService {
|
|
|
982
989
|
provider_token: tp.provider_token,
|
|
983
990
|
provider_refresh_token: tp.provider_refresh_token
|
|
984
991
|
};
|
|
985
|
-
this.
|
|
986
|
-
this._emitEvent("SIGNED_IN", tp.user, tp.access_token);
|
|
992
|
+
this._persistTokens(tp.access_token, tp.refresh_token, tp.user, "SIGNED_IN");
|
|
987
993
|
}
|
|
988
994
|
if (res.data && isMfaChallenge(res.data)) {
|
|
989
995
|
const mfa = res.data;
|
|
@@ -1093,8 +1099,7 @@ var AuthService = class extends BaseService {
|
|
|
1093
1099
|
async signInAnonymously() {
|
|
1094
1100
|
const res = await this.request("POST", `${this.prefix}/anonymous`);
|
|
1095
1101
|
if (res.data) {
|
|
1096
|
-
this.
|
|
1097
|
-
this._emitEvent("SIGNED_IN", res.data.user, res.data.access_token);
|
|
1102
|
+
this._persistTokens(res.data.access_token, res.data.refresh_token, res.data.user, "SIGNED_IN");
|
|
1098
1103
|
}
|
|
1099
1104
|
return res;
|
|
1100
1105
|
}
|
|
@@ -1152,9 +1157,19 @@ var AuthService = class extends BaseService {
|
|
|
1152
1157
|
}
|
|
1153
1158
|
/**
|
|
1154
1159
|
* Installe une session à partir d'un jeton d'accès et d'un jeton de rafraîchissement existants (par exemple reçus d'un serveur).
|
|
1160
|
+
* Accepte indifféremment deux chaînes positionnelles `(accessToken, refreshToken)` ou un objet `{ access_token, refresh_token }` (parité DX Supabase).
|
|
1155
1161
|
* Un jeton d'accès expiré est rafraîchi ; une session invalide est refusée et l'état précédent est restauré.
|
|
1156
1162
|
*/
|
|
1157
|
-
async setSession(
|
|
1163
|
+
async setSession(tokenOrSession, possibleRefreshToken) {
|
|
1164
|
+
let accessToken;
|
|
1165
|
+
let refreshToken;
|
|
1166
|
+
if (typeof tokenOrSession === "object" && tokenOrSession !== null) {
|
|
1167
|
+
accessToken = tokenOrSession.access_token || "";
|
|
1168
|
+
refreshToken = tokenOrSession.refresh_token || "";
|
|
1169
|
+
} else {
|
|
1170
|
+
accessToken = tokenOrSession || "";
|
|
1171
|
+
refreshToken = possibleRefreshToken || "";
|
|
1172
|
+
}
|
|
1158
1173
|
const store = this.client.authStore;
|
|
1159
1174
|
const prev = { token: store.token, refreshToken: store.refreshToken, user: store.user };
|
|
1160
1175
|
const hadValidPrev = !!(prev.token && prev.refreshToken && prev.user && prev.user.id);
|
|
@@ -1232,8 +1247,7 @@ var AuthService = class extends BaseService {
|
|
|
1232
1247
|
}
|
|
1233
1248
|
if (res.data) {
|
|
1234
1249
|
const tp = res.data;
|
|
1235
|
-
this.
|
|
1236
|
-
this._emitEvent(successEvent, tp.user, tp.access_token);
|
|
1250
|
+
this._persistTokens(tp.access_token, tp.refresh_token, tp.user, successEvent);
|
|
1237
1251
|
}
|
|
1238
1252
|
return res;
|
|
1239
1253
|
} finally {
|
|
@@ -1641,8 +1655,7 @@ var AuthService = class extends BaseService {
|
|
|
1641
1655
|
credential: assertionToJson(cred)
|
|
1642
1656
|
});
|
|
1643
1657
|
if (res.data) {
|
|
1644
|
-
this.
|
|
1645
|
-
this._emitEvent("SIGNED_IN", res.data.user, res.data.access_token);
|
|
1658
|
+
this._persistTokens(res.data.access_token, res.data.refresh_token, res.data.user, "SIGNED_IN");
|
|
1646
1659
|
}
|
|
1647
1660
|
return res;
|
|
1648
1661
|
}
|
|
@@ -1693,8 +1706,7 @@ var AuthService = class extends BaseService {
|
|
|
1693
1706
|
provider_token: tp.provider_token,
|
|
1694
1707
|
provider_refresh_token: tp.provider_refresh_token
|
|
1695
1708
|
};
|
|
1696
|
-
this.
|
|
1697
|
-
this._emitEvent("SIGNED_IN", tp.user, tp.access_token);
|
|
1709
|
+
this._persistTokens(tp.access_token, tp.refresh_token, tp.user, "SIGNED_IN");
|
|
1698
1710
|
}
|
|
1699
1711
|
return res;
|
|
1700
1712
|
}
|
|
@@ -1764,8 +1776,7 @@ var AuthService = class extends BaseService {
|
|
|
1764
1776
|
async _verifyToTokenPair(path, body) {
|
|
1765
1777
|
const res = await this.request("POST", path, body);
|
|
1766
1778
|
if (res.data) {
|
|
1767
|
-
this.
|
|
1768
|
-
this._emitEvent("SIGNED_IN", res.data.user, res.data.access_token);
|
|
1779
|
+
this._persistTokens(res.data.access_token, res.data.refresh_token, res.data.user, "SIGNED_IN");
|
|
1769
1780
|
}
|
|
1770
1781
|
return res;
|
|
1771
1782
|
}
|
|
@@ -1838,8 +1849,7 @@ var AuthService = class extends BaseService {
|
|
|
1838
1849
|
}
|
|
1839
1850
|
if (res.data) {
|
|
1840
1851
|
const tp = res.data;
|
|
1841
|
-
this.
|
|
1842
|
-
this._emitEvent("SIGNED_IN", tp.user, tp.access_token);
|
|
1852
|
+
this._persistTokens(tp.access_token, tp.refresh_token, tp.user, "SIGNED_IN");
|
|
1843
1853
|
}
|
|
1844
1854
|
return res;
|
|
1845
1855
|
}
|
|
@@ -1873,8 +1883,12 @@ var AuthService = class extends BaseService {
|
|
|
1873
1883
|
credentials
|
|
1874
1884
|
);
|
|
1875
1885
|
if (res.data) {
|
|
1876
|
-
this.
|
|
1877
|
-
|
|
1886
|
+
this._persistTokens(
|
|
1887
|
+
res.data.access_token,
|
|
1888
|
+
res.data.refresh_token,
|
|
1889
|
+
res.data.user,
|
|
1890
|
+
"USER_UPDATED"
|
|
1891
|
+
);
|
|
1878
1892
|
}
|
|
1879
1893
|
return res;
|
|
1880
1894
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aurabase/auth",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.5",
|
|
4
4
|
"description": "Service d'authentification du SDK Aurabase (sessions, OAuth/PKCE, MFA, magic link, OTP, admin)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -46,13 +46,13 @@
|
|
|
46
46
|
"authentication"
|
|
47
47
|
],
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@aurabase/core": "0.7.
|
|
49
|
+
"@aurabase/core": "0.7.5"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/node": "20.14.15",
|
|
53
53
|
"tsup": "^8.0.0",
|
|
54
54
|
"typescript": "^5.5.0",
|
|
55
|
-
"vitest": "^4.1.
|
|
55
|
+
"vitest": "^4.1.12"
|
|
56
56
|
},
|
|
57
57
|
"scripts": {
|
|
58
58
|
"build": "tsup",
|