@erikey/react 0.1.3 → 0.1.5

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
@@ -1697,7 +1697,7 @@ function createAuthClient2(config) {
1697
1697
  * Get the current authenticated user
1698
1698
  */
1699
1699
  getUser: async () => {
1700
- return fetchWithAuth("/session", {
1700
+ return fetchWithAuth("/get-session", {
1701
1701
  method: "GET"
1702
1702
  });
1703
1703
  },
@@ -1997,19 +1997,23 @@ function createAuthClient3(config) {
1997
1997
  },
1998
1998
  getUser: async () => {
1999
1999
  const result = await client.getUser();
2000
- if (result.success) {
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) {
2001
2003
  return result;
2002
2004
  }
2003
2005
  const token = getStoredToken(projectId);
2004
2006
  if (token) {
2005
- const response = await fetch(`${baseUrl}/api/auth/session`, {
2007
+ console.log("[Sandpack Auth] Cookie auth returned no user, trying Bearer token");
2008
+ const response = await fetch(`${baseUrl}/api/auth/get-session`, {
2006
2009
  headers: {
2007
2010
  "Authorization": `Bearer ${token}`,
2008
2011
  "X-Project-Id": projectId
2009
2012
  }
2010
2013
  });
2011
2014
  const data = await response.json();
2012
- if (response.ok) {
2015
+ if (response.ok && (data?.user || data?.email)) {
2016
+ console.log("[Sandpack Auth] Bearer token auth successful");
2013
2017
  return { success: true, data };
2014
2018
  }
2015
2019
  }