I'm using nextjs app router and isAuth is not getting called! layout.js: //…
- User
I'm using nextjs app router and isAuth is not getting called! layout.js: // app/layout.js import "./globals.css"; import localFont from "next/font/local"; import { Figtree } from "next/font/google"; import NextTopLoader from 'nextjs-toploader'; import StoreProvider from "@/app/StoreProvider"; import Head from "next/head"; import React from "react"; import isAuth from "@/components/isAuth" export const figtree = Figtree({ subsets: ["latin"], variable: "--fig", display: "swap" }); const nnFont = localFont({ src: [ { path: "./fonts/nn-regular.woff2", weight: "400", style: "normal", }, { path: "./fonts/nn-medium.woff2", weight: "500", style: "normal", }, ], variable: "--nn-font", display: "swap" });
export const metadata = { title: "Naay Store", description: "An Iraqi store for makeups", };
export default function RootLayout({ children }) { return ( Naay Store <body className={
m-4 box-border overflow-x-hidden ${nnFont.variable} ${figtree.variable}}> {children} ); } 'use client' import { useEffect } from 'react'; import { setIsAuthenticated } from "@/lib/features/authSlice"; import { setAddresses } from "@/lib/features/addressesSlice"; import { setUserInfo } from "@/lib/features/userSlice"; import { useAppDispatch } from "@/lib/hook";export default function IsAuth() { const dispatch = useAppDispatch();
useEffect(() => { async function checkAuth() { console.log('test') const response = await fetch('https://api.naayiq.com/user/check-auth', {credentials: "include"}); const data = await response.json(); if (data.isAuthenticated) { handleAuthResponse(data, dispatch); } } checkAuth(); }, [dispatch]); return null; // This component doesn't render anything}
function handleAuthResponse(data, dispatch) { if (data.isAuthenticated) { dispatch(setIsAuthenticated(true)); dispatch(setAddresses(data.addresses)); dispatch(setUserInfo({ userId: data.userId, name: data.name, email: data.email, phone: data.phone, dob: data.dob, role: data.role })); } else { dispatch(setIsAuthenticated(false)); dispatch(setAddresses([])); dispatch(setUserInfo({})) } }
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.