@coreiam/auth 1.0.10 → 1.0.12

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.
@@ -4,7 +4,7 @@ export interface AuthResult {
4
4
  status: number;
5
5
  data: any;
6
6
  }
7
- export declare function getSession(): Promise<CoreIAMIdentity | null>;
7
+ export declare const getSession: () => Promise<CoreIAMIdentity | null>;
8
8
  export declare function loginActionSdk(identifier: string, password: string): Promise<AuthResult>;
9
9
  export declare function registerActionSdk(userData: any): Promise<AuthResult>;
10
10
  export declare function logoutActionSdk(): Promise<AuthResult>;
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
- // src/nextjs/actions.ts
3
- // REMOVE 'use server' from here.
4
2
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.getSession = getSession;
3
+ exports.getSession = void 0;
6
4
  exports.loginActionSdk = loginActionSdk;
7
5
  exports.registerActionSdk = registerActionSdk;
8
6
  exports.logoutActionSdk = logoutActionSdk;
7
+ // src/nextjs/actions.ts
8
+ // REMOVE 'use server' from here.
9
+ const react_1 = require("react");
9
10
  const headers_1 = require("next/headers");
10
11
  const core_1 = require("../core");
11
12
  let _iam = null;
@@ -59,8 +60,16 @@ async function syncCookiesToNext(response) {
59
60
  }
60
61
  }
61
62
  }
62
- // This is called by Server Components (e.g., layout.tsx)
63
- async function getSession() {
63
+ // // This is called by Server Components (e.g., layout.tsx)
64
+ // export async function getSession(): Promise<CoreIAMIdentity | null> {
65
+ // const reqHeaders = await headers();
66
+ // const response = await getIam().proxy('/auth/profile', { method: 'GET' }, reqHeaders);
67
+ // if (!response.ok) return null;
68
+ // const coreIamIdentity = await response.json();
69
+ // if (!coreIamIdentity?.sub) return null;
70
+ // return coreIamIdentity as CoreIAMIdentity;
71
+ // }
72
+ exports.getSession = (0, react_1.cache)(async () => {
64
73
  const reqHeaders = await (0, headers_1.headers)();
65
74
  const response = await getIam().proxy('/auth/profile', { method: 'GET' }, reqHeaders);
66
75
  if (!response.ok)
@@ -69,7 +78,7 @@ async function getSession() {
69
78
  if (!coreIamIdentity?.sub)
70
79
  return null;
71
80
  return coreIamIdentity;
72
- }
81
+ });
73
82
  // These are no longer called by the SDK's provider.tsx,
74
83
  // but can still be used by Qalam's Server Actions if needed.
75
84
  async function loginActionSdk(identifier, password) {
@@ -42,6 +42,40 @@ function CoreIAMProvider({ children, initialIdentity, redirects = {}, }) {
42
42
  }
43
43
  // eslint-disable-next-line react-hooks/exhaustive-deps
44
44
  }, []);
45
+ // const login = async (values: { email: string; password: string }, callbackUrl?: string): Promise<LoginResult> => {
46
+ // setIsLoading(true);
47
+ // try {
48
+ // // Fetch CSRF token first
49
+ // const csrfRes = await fetch('/api/auth/csrf', { credentials: 'include' });
50
+ // if (!csrfRes.ok) return { error: 'Failed to get CSRF token' };
51
+ // const { csrfToken } = await csrfRes.json();
52
+ // // Call login API route
53
+ // const loginRes = await fetch('/api/auth/login', {
54
+ // method: 'POST',
55
+ // headers: {
56
+ // 'Content-Type': 'application/json',
57
+ // 'x-csrf-token': csrfToken,
58
+ // },
59
+ // credentials: 'include',
60
+ // body: JSON.stringify(values),
61
+ // });
62
+ // const data = await loginRes.json();
63
+ // if (!loginRes.ok) {
64
+ // return { error: data.message || data.error || 'Invalid credentials' };
65
+ // }
66
+ // if (data.twoFactor) {
67
+ // return { twoFactor: true };
68
+ // }
69
+ // await refetchIdentity();
70
+ // const target = callbackUrl || redirects.afterLogin;
71
+ // if (target) router.push(target);
72
+ // return { success: true };
73
+ // } catch {
74
+ // return { error: 'Something went wrong' };
75
+ // } finally {
76
+ // setIsLoading(false);
77
+ // }
78
+ // };
45
79
  const login = async (values, callbackUrl) => {
46
80
  setIsLoading(true);
47
81
  try {
@@ -50,6 +84,11 @@ function CoreIAMProvider({ children, initialIdentity, redirects = {}, }) {
50
84
  if (!csrfRes.ok)
51
85
  return { error: 'Failed to get CSRF token' };
52
86
  const { csrfToken } = await csrfRes.json();
87
+ // FIX: Map 'email' to 'identifier' for the CoreIAM backend
88
+ const loginPayload = {
89
+ identifier: values.email,
90
+ password: values.password,
91
+ };
53
92
  // Call login API route
54
93
  const loginRes = await fetch('/api/auth/login', {
55
94
  method: 'POST',
@@ -58,7 +97,7 @@ function CoreIAMProvider({ children, initialIdentity, redirects = {}, }) {
58
97
  'x-csrf-token': csrfToken,
59
98
  },
60
99
  credentials: 'include',
61
- body: JSON.stringify(values),
100
+ body: JSON.stringify(loginPayload), // Send the mapped payload
62
101
  });
63
102
  const data = await loginRes.json();
64
103
  if (!loginRes.ok) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coreiam/auth",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "main": "./dist/core/index.js",
5
5
  "types": "./dist/core/index.d.ts",
6
6
  "exports": {