fixed login session for user name, and updated the api calls on the product detials pages.
CI / test (push) Successful in 6s
CI / test (push) Successful in 6s
This commit is contained in:
+11
-3
@@ -75,7 +75,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
}
|
||||
|
||||
// Verify session with server
|
||||
fetch("/api/auth/me")
|
||||
fetch("/api/auth/me", { credentials: 'include' })
|
||||
.then((res) => {
|
||||
if (res.ok) {
|
||||
return res.json();
|
||||
@@ -104,7 +104,10 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
}, [persistUser]);
|
||||
|
||||
const refreshUser = useCallback(async () => {
|
||||
const res = await fetch("/api/auth/me", { cache: "no-store" });
|
||||
const res = await fetch("/api/auth/me", {
|
||||
cache: "no-store",
|
||||
credentials: 'include',
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
const text = await res.text().catch(() => res.statusText);
|
||||
@@ -133,6 +136,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
const res = await fetch("/api/auth/login", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
credentials: 'include',
|
||||
body: JSON.stringify({ email, password }),
|
||||
});
|
||||
|
||||
@@ -167,6 +171,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
const res = await fetch("/api/auth/register", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
credentials: 'include',
|
||||
body: JSON.stringify({
|
||||
email,
|
||||
password,
|
||||
@@ -199,7 +204,10 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
persistUser(null);
|
||||
|
||||
// Clear server session cookies
|
||||
fetch("/api/auth/logout", { method: "POST" }).catch(() => {});
|
||||
fetch("/api/auth/logout", {
|
||||
method: "POST",
|
||||
credentials: 'include',
|
||||
}).catch(() => {});
|
||||
}, [persistUser]);
|
||||
|
||||
const value: AuthContextValue = {
|
||||
|
||||
Reference in New Issue
Block a user