@aurabase/auth 0.7.4 → 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 +22 -18
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +22 -18
- 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
|
}
|
|
@@ -1244,8 +1249,7 @@ var AuthService = class extends core.BaseService {
|
|
|
1244
1249
|
}
|
|
1245
1250
|
if (res.data) {
|
|
1246
1251
|
const tp = res.data;
|
|
1247
|
-
this.
|
|
1248
|
-
this._emitEvent(successEvent, tp.user, tp.access_token);
|
|
1252
|
+
this._persistTokens(tp.access_token, tp.refresh_token, tp.user, successEvent);
|
|
1249
1253
|
}
|
|
1250
1254
|
return res;
|
|
1251
1255
|
} finally {
|
|
@@ -1653,8 +1657,7 @@ var AuthService = class extends core.BaseService {
|
|
|
1653
1657
|
credential: assertionToJson(cred)
|
|
1654
1658
|
});
|
|
1655
1659
|
if (res.data) {
|
|
1656
|
-
this.
|
|
1657
|
-
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");
|
|
1658
1661
|
}
|
|
1659
1662
|
return res;
|
|
1660
1663
|
}
|
|
@@ -1705,8 +1708,7 @@ var AuthService = class extends core.BaseService {
|
|
|
1705
1708
|
provider_token: tp.provider_token,
|
|
1706
1709
|
provider_refresh_token: tp.provider_refresh_token
|
|
1707
1710
|
};
|
|
1708
|
-
this.
|
|
1709
|
-
this._emitEvent("SIGNED_IN", tp.user, tp.access_token);
|
|
1711
|
+
this._persistTokens(tp.access_token, tp.refresh_token, tp.user, "SIGNED_IN");
|
|
1710
1712
|
}
|
|
1711
1713
|
return res;
|
|
1712
1714
|
}
|
|
@@ -1776,8 +1778,7 @@ var AuthService = class extends core.BaseService {
|
|
|
1776
1778
|
async _verifyToTokenPair(path, body) {
|
|
1777
1779
|
const res = await this.request("POST", path, body);
|
|
1778
1780
|
if (res.data) {
|
|
1779
|
-
this.
|
|
1780
|
-
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");
|
|
1781
1782
|
}
|
|
1782
1783
|
return res;
|
|
1783
1784
|
}
|
|
@@ -1850,8 +1851,7 @@ var AuthService = class extends core.BaseService {
|
|
|
1850
1851
|
}
|
|
1851
1852
|
if (res.data) {
|
|
1852
1853
|
const tp = res.data;
|
|
1853
|
-
this.
|
|
1854
|
-
this._emitEvent("SIGNED_IN", tp.user, tp.access_token);
|
|
1854
|
+
this._persistTokens(tp.access_token, tp.refresh_token, tp.user, "SIGNED_IN");
|
|
1855
1855
|
}
|
|
1856
1856
|
return res;
|
|
1857
1857
|
}
|
|
@@ -1885,8 +1885,12 @@ var AuthService = class extends core.BaseService {
|
|
|
1885
1885
|
credentials
|
|
1886
1886
|
);
|
|
1887
1887
|
if (res.data) {
|
|
1888
|
-
this.
|
|
1889
|
-
|
|
1888
|
+
this._persistTokens(
|
|
1889
|
+
res.data.access_token,
|
|
1890
|
+
res.data.refresh_token,
|
|
1891
|
+
res.data.user,
|
|
1892
|
+
"USER_UPDATED"
|
|
1893
|
+
);
|
|
1890
1894
|
}
|
|
1891
1895
|
return res;
|
|
1892
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
|
/**
|
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
|
/**
|
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
|
}
|
|
@@ -1242,8 +1247,7 @@ var AuthService = class extends BaseService {
|
|
|
1242
1247
|
}
|
|
1243
1248
|
if (res.data) {
|
|
1244
1249
|
const tp = res.data;
|
|
1245
|
-
this.
|
|
1246
|
-
this._emitEvent(successEvent, tp.user, tp.access_token);
|
|
1250
|
+
this._persistTokens(tp.access_token, tp.refresh_token, tp.user, successEvent);
|
|
1247
1251
|
}
|
|
1248
1252
|
return res;
|
|
1249
1253
|
} finally {
|
|
@@ -1651,8 +1655,7 @@ var AuthService = class extends BaseService {
|
|
|
1651
1655
|
credential: assertionToJson(cred)
|
|
1652
1656
|
});
|
|
1653
1657
|
if (res.data) {
|
|
1654
|
-
this.
|
|
1655
|
-
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");
|
|
1656
1659
|
}
|
|
1657
1660
|
return res;
|
|
1658
1661
|
}
|
|
@@ -1703,8 +1706,7 @@ var AuthService = class extends BaseService {
|
|
|
1703
1706
|
provider_token: tp.provider_token,
|
|
1704
1707
|
provider_refresh_token: tp.provider_refresh_token
|
|
1705
1708
|
};
|
|
1706
|
-
this.
|
|
1707
|
-
this._emitEvent("SIGNED_IN", tp.user, tp.access_token);
|
|
1709
|
+
this._persistTokens(tp.access_token, tp.refresh_token, tp.user, "SIGNED_IN");
|
|
1708
1710
|
}
|
|
1709
1711
|
return res;
|
|
1710
1712
|
}
|
|
@@ -1774,8 +1776,7 @@ var AuthService = class extends BaseService {
|
|
|
1774
1776
|
async _verifyToTokenPair(path, body) {
|
|
1775
1777
|
const res = await this.request("POST", path, body);
|
|
1776
1778
|
if (res.data) {
|
|
1777
|
-
this.
|
|
1778
|
-
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");
|
|
1779
1780
|
}
|
|
1780
1781
|
return res;
|
|
1781
1782
|
}
|
|
@@ -1848,8 +1849,7 @@ var AuthService = class extends BaseService {
|
|
|
1848
1849
|
}
|
|
1849
1850
|
if (res.data) {
|
|
1850
1851
|
const tp = res.data;
|
|
1851
|
-
this.
|
|
1852
|
-
this._emitEvent("SIGNED_IN", tp.user, tp.access_token);
|
|
1852
|
+
this._persistTokens(tp.access_token, tp.refresh_token, tp.user, "SIGNED_IN");
|
|
1853
1853
|
}
|
|
1854
1854
|
return res;
|
|
1855
1855
|
}
|
|
@@ -1883,8 +1883,12 @@ var AuthService = class extends BaseService {
|
|
|
1883
1883
|
credentials
|
|
1884
1884
|
);
|
|
1885
1885
|
if (res.data) {
|
|
1886
|
-
this.
|
|
1887
|
-
|
|
1886
|
+
this._persistTokens(
|
|
1887
|
+
res.data.access_token,
|
|
1888
|
+
res.data.refresh_token,
|
|
1889
|
+
res.data.user,
|
|
1890
|
+
"USER_UPDATED"
|
|
1891
|
+
);
|
|
1888
1892
|
}
|
|
1889
1893
|
return res;
|
|
1890
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",
|