Commit a1188f74 by Arjun Jhukal

made the server and client private component similar

parent ff982c05
......@@ -5,7 +5,6 @@ import React from 'react'
export default function PrivateUserLayout({ children }: { children: React.ReactNode }) {
return (
<ServerPrivate>
<DashboardLayout>
{children}
</DashboardLayout>
......
......@@ -73,6 +73,11 @@ export default function LoginPage() {
secure: process.env.NODE_ENV === 'production',
sameSite: 'Strict',
});
Cookies.set('user', JSON.stringify(response?.data?.user), {
expires: 1,
secure: process.env.NODE_ENV === 'production',
sameSite: 'Strict',
});
router.replace(PATH.DASHBOARD.ROOT);
}
catch (e: any) {
......
......@@ -40,10 +40,10 @@ export default function CoinCalculator({ slug }: { slug: string }) {
};
const handleBuy = () => {
if (Number(amount) < 20) {
if (Number(amount) < 2) {
return dispatch(
showToast({
message: "Minimum amount is 20",
message: "Minimum amount is 2",
variant: ToastVariant.ERROR,
})
)
......
......@@ -14,16 +14,6 @@ import PaymentForm from './FortPay';
export type PaymentModeProps = "crypto" | "fortpay"
/**
* Before redirecting to an external payment gateway, we back up every auth-related
* key from localStorage into sessionStorage.
*
* Why sessionStorage?
* - It survives external redirects (the tab stays open, session is preserved).
* - It is scoped to the tab, so it won't leak to other tabs.
* - Unlike localStorage it won't be touched by any app boot logic that
* reinitialises the store and accidentally clears auth keys.
*/
const AUTH_KEYS = ['token', 'access_token', 'authToken', 'user', 'refresh_token'];
const BACKUP_PREFIX = '__payment_backup__';
......@@ -173,8 +163,8 @@ export default function CheckoutPage({ amount, slug, bonus }: {
backupAuthToSession();
window.location.href = response?.data?.payment_url;
window.open(response?.data?.payment_url, "_blank");
// window.location.href = response?.data?.payment_url;
} catch (e: any) {
dispatch(
......
"use client";
import { User } from "@/types/auth";
export default function ReduxHydrator({ token }: { token: string; }) {
console.log(token);
export default function ReduxHydrator({ token, user }: { token: string; user: User }) {
console.log({ token, user });
// useEffect(() => {
// dispatch(setTokens({ access_token: token, user }));
......
......@@ -12,24 +12,16 @@ import ReduxHydrator from "./ReduxHydrator";
// }
export default async function ServerPrivate({ children }: { children: React.ReactNode }) {
// ✅ Read cookie server-side
const cookieStore = await cookies();
const access_token = cookieStore.get("access_token")?.value;
if (!access_token) return;
// const payload = decodeJwt(access_token);
// if (!payload || !payload.exp || payload.exp < Math.floor(Date.now() / 1000)) {
// redirect("/");
// }
// const user = payload;
const user_cookie = cookieStore.get("user")?.value;
const user = user_cookie ? JSON.parse(user_cookie) : null;
if (!access_token||!user) return;
return (
<>
{/* ✅ Hydrate Redux store on client */}
<ReduxHydrator token={access_token} />
<ReduxHydrator token={access_token} user={user}/>
{children}
</>
);
......
......@@ -61,6 +61,7 @@ export const authSlice = createSlice({
localStorage.removeItem("token");
}
Cookies.remove("access_token");
Cookies.remove("user");
},
}
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment