@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.mjs CHANGED
@@ -1953,15 +1953,27 @@ function createAuthClient3(config) {
1953
1953
  return {
1954
1954
  signUp: async (data) => {
1955
1955
  const result = await client.signUp(data);
1956
- if (result.success && result.data?.session) {
1957
- storeToken(projectId, result.data.session);
1956
+ const token = result.data?.token || result.data?.session?.token;
1957
+ if (result.success && token) {
1958
+ console.log("[Sandpack Auth] Storing token after sign-up");
1959
+ storeToken(projectId, {
1960
+ token,
1961
+ expiresAt: new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3).toISOString()
1962
+ // 7 days
1963
+ });
1958
1964
  }
1959
1965
  return result;
1960
1966
  },
1961
1967
  signIn: async (data) => {
1962
1968
  const result = await client.signIn(data);
1963
- if (result.success && result.data?.session) {
1964
- storeToken(projectId, result.data.session);
1969
+ const token = result.data?.token || result.data?.session?.token;
1970
+ if (result.success && token) {
1971
+ console.log("[Sandpack Auth] Storing token after sign-in");
1972
+ storeToken(projectId, {
1973
+ token,
1974
+ expiresAt: new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3).toISOString()
1975
+ // 7 days
1976
+ });
1965
1977
  }
1966
1978
  return result;
1967
1979
  },
@@ -1972,19 +1984,23 @@ function createAuthClient3(config) {
1972
1984
  },
1973
1985
  getUser: async () => {
1974
1986
  const result = await client.getUser();
1975
- if (result.success) {
1987
+ const hasUser = result.success && result.data && ("email" in result.data || // Direct User object
1988
+ "user" in result.data && result.data.user);
1989
+ if (hasUser) {
1976
1990
  return result;
1977
1991
  }
1978
1992
  const token = getStoredToken(projectId);
1979
1993
  if (token) {
1980
- const response = await fetch(`${baseUrl}/api/auth/session`, {
1994
+ console.log("[Sandpack Auth] Cookie auth returned no user, trying Bearer token");
1995
+ const response = await fetch(`${baseUrl}/api/auth/get-session`, {
1981
1996
  headers: {
1982
1997
  "Authorization": `Bearer ${token}`,
1983
1998
  "X-Project-Id": projectId
1984
1999
  }
1985
2000
  });
1986
2001
  const data = await response.json();
1987
- if (response.ok) {
2002
+ if (response.ok && (data?.user || data?.email)) {
2003
+ console.log("[Sandpack Auth] Bearer token auth successful");
1988
2004
  return { success: true, data };
1989
2005
  }
1990
2006
  }