@coreiam/auth 1.0.10 → 1.0.11

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.
@@ -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.11",
4
4
  "main": "./dist/core/index.js",
5
5
  "types": "./dist/core/index.d.ts",
6
6
  "exports": {