@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.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
|
-
|
|
1957
|
-
|
|
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
|
-
|
|
1964
|
-
|
|
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
|
},
|
|
@@ -1971,15 +1983,8 @@ function createAuthClient3(config) {
|
|
|
1971
1983
|
return result;
|
|
1972
1984
|
},
|
|
1973
1985
|
getUser: async () => {
|
|
1974
|
-
const result = await client.getUser();
|
|
1975
|
-
const hasUser = result.success && result.data && ("email" in result.data || // Direct User object
|
|
1976
|
-
"user" in result.data && result.data.user);
|
|
1977
|
-
if (hasUser) {
|
|
1978
|
-
return result;
|
|
1979
|
-
}
|
|
1980
1986
|
const token = getStoredToken(projectId);
|
|
1981
1987
|
if (token) {
|
|
1982
|
-
console.log("[Sandpack Auth] Cookie auth returned no user, trying Bearer token");
|
|
1983
1988
|
const response = await fetch(`${baseUrl}/api/auth/get-session`, {
|
|
1984
1989
|
headers: {
|
|
1985
1990
|
"Authorization": `Bearer ${token}`,
|
|
@@ -1988,11 +1993,12 @@ function createAuthClient3(config) {
|
|
|
1988
1993
|
});
|
|
1989
1994
|
const data = await response.json();
|
|
1990
1995
|
if (response.ok && (data?.user || data?.email)) {
|
|
1991
|
-
console.log("[Sandpack Auth] Bearer token auth successful");
|
|
1992
1996
|
return { success: true, data };
|
|
1993
1997
|
}
|
|
1998
|
+
console.log("[Sandpack Auth] Bearer token invalid, clearing");
|
|
1999
|
+
clearToken(projectId);
|
|
1994
2000
|
}
|
|
1995
|
-
return
|
|
2001
|
+
return { success: true, data: void 0 };
|
|
1996
2002
|
},
|
|
1997
2003
|
forgotPassword: client.forgotPassword,
|
|
1998
2004
|
resetPassword: client.resetPassword,
|