@erikey/react 0.1.4 → 0.1.6

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 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
- if (result.success && result.data?.session) {
1982
- storeToken(projectId, result.data.session);
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
- if (result.success && result.data?.session) {
1989
- storeToken(projectId, result.data.session);
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
  },
@@ -1997,19 +2009,23 @@ function createAuthClient3(config) {
1997
2009
  },
1998
2010
  getUser: async () => {
1999
2011
  const result = await client.getUser();
2000
- if (result.success) {
2012
+ const hasUser = result.success && result.data && ("email" in result.data || // Direct User object
2013
+ "user" in result.data && result.data.user);
2014
+ if (hasUser) {
2001
2015
  return result;
2002
2016
  }
2003
2017
  const token = getStoredToken(projectId);
2004
2018
  if (token) {
2005
- const response = await fetch(`${baseUrl}/api/auth/session`, {
2019
+ console.log("[Sandpack Auth] Cookie auth returned no user, trying Bearer token");
2020
+ const response = await fetch(`${baseUrl}/api/auth/get-session`, {
2006
2021
  headers: {
2007
2022
  "Authorization": `Bearer ${token}`,
2008
2023
  "X-Project-Id": projectId
2009
2024
  }
2010
2025
  });
2011
2026
  const data = await response.json();
2012
- if (response.ok) {
2027
+ if (response.ok && (data?.user || data?.email)) {
2028
+ console.log("[Sandpack Auth] Bearer token auth successful");
2013
2029
  return { success: true, data };
2014
2030
  }
2015
2031
  }