@coreiam/auth 1.0.0 → 1.0.1
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/core/index.d.ts +7 -0
- package/dist/nextjs/actions.d.ts +2 -1
- package/dist/nextjs/actions.js +20 -15
- package/package.json +1 -1
package/dist/core/index.d.ts
CHANGED
|
@@ -3,6 +3,13 @@ export interface CoreIAMConfig {
|
|
|
3
3
|
apiKey?: string;
|
|
4
4
|
tenantId?: string;
|
|
5
5
|
}
|
|
6
|
+
export interface CoreIAMIdentity {
|
|
7
|
+
sub: string;
|
|
8
|
+
email?: string;
|
|
9
|
+
tenantId?: string;
|
|
10
|
+
roles?: string[];
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
}
|
|
6
13
|
export declare class CoreIAM {
|
|
7
14
|
private apiKey;
|
|
8
15
|
private baseUrl;
|
package/dist/nextjs/actions.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CoreIAMIdentity } from '../core';
|
|
1
2
|
export interface AuthResult {
|
|
2
3
|
ok: boolean;
|
|
3
4
|
status: number;
|
|
@@ -7,7 +8,7 @@ export interface AuthResult {
|
|
|
7
8
|
* NEW: Securely gets the user session.
|
|
8
9
|
* Handles 401 by attempting a silent refresh internally.
|
|
9
10
|
*/
|
|
10
|
-
export declare function getSession(): Promise<
|
|
11
|
+
export declare function getSession(): Promise<CoreIAMIdentity | null>;
|
|
11
12
|
export declare function loginActionSdk(identifier: string, password: string): Promise<AuthResult>;
|
|
12
13
|
export declare function registerActionSdk(userData: any): Promise<AuthResult>;
|
|
13
14
|
export declare function logoutActionSdk(): Promise<AuthResult>;
|
package/dist/nextjs/actions.js
CHANGED
|
@@ -66,26 +66,31 @@ async function getSession() {
|
|
|
66
66
|
const reqHeaders = await (0, headers_1.headers)();
|
|
67
67
|
let response = await iam.proxy('/auth/profile', { method: 'GET' }, reqHeaders);
|
|
68
68
|
if (response.status === 401) {
|
|
69
|
-
const
|
|
70
|
-
if (
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
69
|
+
const refreshRes = await iam.proxy('/auth/refresh-token', { method: 'POST' }, reqHeaders);
|
|
70
|
+
if (refreshRes.ok) {
|
|
71
|
+
const setCookies = refreshRes.headers.getSetCookie();
|
|
72
|
+
if (setCookies && setCookies.length > 0) {
|
|
73
|
+
const fakeRes = new Response(null, { headers: { 'set-cookie': setCookies.join(', ') } });
|
|
74
|
+
await syncCookiesToNext(fakeRes);
|
|
75
|
+
const cookieStore = await (0, headers_1.cookies)();
|
|
76
|
+
const newJwt = cookieStore.get('jwt')?.value;
|
|
77
|
+
const newRefresh = cookieStore.get('refreshToken')?.value;
|
|
78
|
+
const retryHeaders = new Headers(reqHeaders);
|
|
79
|
+
if (newJwt && newRefresh) {
|
|
80
|
+
retryHeaders.set('cookie', `jwt=${newJwt}; refreshToken=${newRefresh}`);
|
|
81
|
+
retryHeaders.set('Authorization', `Bearer ${newJwt}`);
|
|
82
|
+
}
|
|
83
|
+
response = await iam.proxy('/auth/profile', { method: 'GET' }, retryHeaders);
|
|
82
84
|
}
|
|
83
|
-
response = await iam.proxy('/auth/profile', { method: 'GET' }, retryHeaders);
|
|
84
85
|
}
|
|
85
86
|
}
|
|
86
87
|
if (!response.ok)
|
|
87
88
|
return null;
|
|
88
|
-
|
|
89
|
+
const coreIamIdentity = await response.json();
|
|
90
|
+
if (!coreIamIdentity?.sub)
|
|
91
|
+
return null;
|
|
92
|
+
// Return the Provider's Identity, NOT the Customer's User
|
|
93
|
+
return coreIamIdentity;
|
|
89
94
|
}
|
|
90
95
|
async function loginActionSdk(identifier, password) {
|
|
91
96
|
const reqHeaders = await (0, headers_1.headers)();
|