@insforge/sdk 1.0.7 → 1.1.0-dev.0
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.d.mts +0 -10
- package/dist/index.d.ts +0 -10
- package/dist/index.js +16 -49
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +16 -49
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -379,17 +379,18 @@ var Auth = class {
|
|
|
379
379
|
*/
|
|
380
380
|
async signUp(request) {
|
|
381
381
|
try {
|
|
382
|
-
const response = await this.http.post("/api/auth/users", request);
|
|
382
|
+
const response = await this.http.post("/api/auth/users", request, { credentials: "include" });
|
|
383
383
|
if (response.accessToken && response.user && !isHostedAuthEnvironment()) {
|
|
384
384
|
const session = {
|
|
385
385
|
accessToken: response.accessToken,
|
|
386
386
|
user: response.user
|
|
387
387
|
};
|
|
388
|
-
this.tokenManager.saveSession(session);
|
|
389
|
-
this.http.setAuthToken(response.accessToken);
|
|
390
388
|
if (response.csrfToken) {
|
|
389
|
+
this.tokenManager.setMemoryMode();
|
|
391
390
|
setCsrfToken(response.csrfToken);
|
|
392
391
|
}
|
|
392
|
+
this.tokenManager.saveSession(session);
|
|
393
|
+
this.http.setAuthToken(response.accessToken);
|
|
393
394
|
}
|
|
394
395
|
return {
|
|
395
396
|
data: response,
|
|
@@ -414,17 +415,18 @@ var Auth = class {
|
|
|
414
415
|
*/
|
|
415
416
|
async signInWithPassword(request) {
|
|
416
417
|
try {
|
|
417
|
-
const response = await this.http.post("/api/auth/sessions", request);
|
|
418
|
+
const response = await this.http.post("/api/auth/sessions", request, { credentials: "include" });
|
|
418
419
|
if (!isHostedAuthEnvironment()) {
|
|
419
420
|
const session = {
|
|
420
421
|
accessToken: response.accessToken,
|
|
421
422
|
user: response.user
|
|
422
423
|
};
|
|
423
|
-
this.tokenManager.saveSession(session);
|
|
424
|
-
this.http.setAuthToken(response.accessToken);
|
|
425
424
|
if (response.csrfToken) {
|
|
425
|
+
this.tokenManager.setMemoryMode();
|
|
426
426
|
setCsrfToken(response.csrfToken);
|
|
427
427
|
}
|
|
428
|
+
this.tokenManager.saveSession(session);
|
|
429
|
+
this.http.setAuthToken(response.accessToken);
|
|
428
430
|
}
|
|
429
431
|
return {
|
|
430
432
|
data: response,
|
|
@@ -538,46 +540,6 @@ var Auth = class {
|
|
|
538
540
|
};
|
|
539
541
|
}
|
|
540
542
|
}
|
|
541
|
-
/**
|
|
542
|
-
* Get the current user with full profile information
|
|
543
|
-
* Returns both auth info (id, email, role) and profile data (dynamic fields from users table)
|
|
544
|
-
*/
|
|
545
|
-
async getCurrentUser() {
|
|
546
|
-
try {
|
|
547
|
-
const user = this.tokenManager.getUser();
|
|
548
|
-
if (user) {
|
|
549
|
-
return { data: { user }, error: null };
|
|
550
|
-
}
|
|
551
|
-
const accessToken = this.tokenManager.getAccessToken();
|
|
552
|
-
if (!accessToken) {
|
|
553
|
-
return { data: null, error: null };
|
|
554
|
-
}
|
|
555
|
-
this.http.setAuthToken(accessToken);
|
|
556
|
-
const authResponse = await this.http.get("/api/auth/sessions/current");
|
|
557
|
-
return {
|
|
558
|
-
data: {
|
|
559
|
-
user: authResponse.user
|
|
560
|
-
},
|
|
561
|
-
error: null
|
|
562
|
-
};
|
|
563
|
-
} catch (error) {
|
|
564
|
-
if (error instanceof InsForgeError && error.statusCode === 401) {
|
|
565
|
-
await this.signOut();
|
|
566
|
-
return { data: null, error: null };
|
|
567
|
-
}
|
|
568
|
-
if (error instanceof InsForgeError) {
|
|
569
|
-
return { data: null, error };
|
|
570
|
-
}
|
|
571
|
-
return {
|
|
572
|
-
data: null,
|
|
573
|
-
error: new InsForgeError(
|
|
574
|
-
"An unexpected error occurred while fetching user",
|
|
575
|
-
500,
|
|
576
|
-
"UNEXPECTED_ERROR"
|
|
577
|
-
)
|
|
578
|
-
};
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
543
|
/**
|
|
582
544
|
* Get any user's profile by ID
|
|
583
545
|
* Returns profile information from the users table
|
|
@@ -608,6 +570,9 @@ var Auth = class {
|
|
|
608
570
|
* Returns the stored JWT token and basic user info from local storage
|
|
609
571
|
*/
|
|
610
572
|
async getCurrentSession() {
|
|
573
|
+
if (isHostedAuthEnvironment()) {
|
|
574
|
+
return { data: { session: null }, error: null };
|
|
575
|
+
}
|
|
611
576
|
try {
|
|
612
577
|
const session = this.tokenManager.getSession();
|
|
613
578
|
if (session) {
|
|
@@ -855,18 +820,20 @@ var Auth = class {
|
|
|
855
820
|
try {
|
|
856
821
|
const response = await this.http.post(
|
|
857
822
|
"/api/auth/email/verify",
|
|
858
|
-
request
|
|
823
|
+
request,
|
|
824
|
+
{ credentials: "include" }
|
|
859
825
|
);
|
|
860
826
|
if (!isHostedAuthEnvironment()) {
|
|
861
827
|
const session = {
|
|
862
828
|
accessToken: response.accessToken,
|
|
863
829
|
user: response.user
|
|
864
830
|
};
|
|
865
|
-
this.tokenManager.saveSession(session);
|
|
866
|
-
this.http.setAuthToken(response.accessToken);
|
|
867
831
|
if (response.csrfToken) {
|
|
832
|
+
this.tokenManager.setMemoryMode();
|
|
868
833
|
setCsrfToken(response.csrfToken);
|
|
869
834
|
}
|
|
835
|
+
this.tokenManager.saveSession(session);
|
|
836
|
+
this.http.setAuthToken(response.accessToken);
|
|
870
837
|
}
|
|
871
838
|
return {
|
|
872
839
|
data: response,
|