@erikey/react 0.1.5 → 0.1.7
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.js +19 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +19 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1978,15 +1978,27 @@ function createAuthClient3(config) {
|
|
|
1978
1978
|
return {
|
|
1979
1979
|
signUp: async (data) => {
|
|
1980
1980
|
const result = await client.signUp(data);
|
|
1981
|
-
|
|
1982
|
-
|
|
1981
|
+
const token = result.data?.token || result.data?.session?.token;
|
|
1982
|
+
if (result.success && token) {
|
|
1983
|
+
console.log("[Sandpack Auth] Storing token after sign-up");
|
|
1984
|
+
storeToken(projectId, {
|
|
1985
|
+
token,
|
|
1986
|
+
expiresAt: new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3).toISOString()
|
|
1987
|
+
// 7 days
|
|
1988
|
+
});
|
|
1983
1989
|
}
|
|
1984
1990
|
return result;
|
|
1985
1991
|
},
|
|
1986
1992
|
signIn: async (data) => {
|
|
1987
1993
|
const result = await client.signIn(data);
|
|
1988
|
-
|
|
1989
|
-
|
|
1994
|
+
const token = result.data?.token || result.data?.session?.token;
|
|
1995
|
+
if (result.success && token) {
|
|
1996
|
+
console.log("[Sandpack Auth] Storing token after sign-in");
|
|
1997
|
+
storeToken(projectId, {
|
|
1998
|
+
token,
|
|
1999
|
+
expiresAt: new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3).toISOString()
|
|
2000
|
+
// 7 days
|
|
2001
|
+
});
|
|
1990
2002
|
}
|
|
1991
2003
|
return result;
|
|
1992
2004
|
},
|
|
@@ -1996,15 +2008,8 @@ function createAuthClient3(config) {
|
|
|
1996
2008
|
return result;
|
|
1997
2009
|
},
|
|
1998
2010
|
getUser: async () => {
|
|
1999
|
-
const result = await client.getUser();
|
|
2000
|
-
const hasUser = result.success && result.data && ("email" in result.data || // Direct User object
|
|
2001
|
-
"user" in result.data && result.data.user);
|
|
2002
|
-
if (hasUser) {
|
|
2003
|
-
return result;
|
|
2004
|
-
}
|
|
2005
2011
|
const token = getStoredToken(projectId);
|
|
2006
2012
|
if (token) {
|
|
2007
|
-
console.log("[Sandpack Auth] Cookie auth returned no user, trying Bearer token");
|
|
2008
2013
|
const response = await fetch(`${baseUrl}/api/auth/get-session`, {
|
|
2009
2014
|
headers: {
|
|
2010
2015
|
"Authorization": `Bearer ${token}`,
|
|
@@ -2013,11 +2018,12 @@ function createAuthClient3(config) {
|
|
|
2013
2018
|
});
|
|
2014
2019
|
const data = await response.json();
|
|
2015
2020
|
if (response.ok && (data?.user || data?.email)) {
|
|
2016
|
-
console.log("[Sandpack Auth] Bearer token auth successful");
|
|
2017
2021
|
return { success: true, data };
|
|
2018
2022
|
}
|
|
2023
|
+
console.log("[Sandpack Auth] Bearer token invalid, clearing");
|
|
2024
|
+
clearToken(projectId);
|
|
2019
2025
|
}
|
|
2020
|
-
return
|
|
2026
|
+
return { success: true, data: void 0 };
|
|
2021
2027
|
},
|
|
2022
2028
|
forgotPassword: client.forgotPassword,
|
|
2023
2029
|
resetPassword: client.resetPassword,
|