You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since we are using i18n router + next auth, it seems like it's tricky to restrict the user who is not logged in using traditional methods. So far I've tried this way but it doesnt work 100% correctly.
// function getLocale(request) {
// let headers = { "accept-language": "en" };
// let languages = new Negotiator({ headers }).languages();
// return match(languages, locales, defaultLocale); // -> 'en'
// }
// export function middleware(request) {
// // cancel if exception
// const pathname = request.nextUrl.pathname;
// const isException = [
// "/img",
// "/preview",
// "/icons",
// "/logo.svg",
// "/api",
// "/manifest.json",
// "/sw.js",
// ].some((allowedPath) => pathname.startsWith(`${allowedPath}`));
// if (isException) return;
// // Check if there is any supported locale in the pathname
// const pathnameIsMissingLocale = locales.every(
// (locale) => !pathname.startsWith(`/${locale}/`) && pathname !== `/${locale}`
// );
// // Redirect if there is no locale
// if (pathnameIsMissingLocale) {
// const locale = getLocale(request);
// return NextResponse.redirect(
// new URL(`/${locale}/${pathname}`, request.url)
// );
// u;
// }
// // check if auth is required
// if (pathname.includes("/dashboard")) {
// const locale = getLocale(request);
// // check & handle if logged in
// const nextAuthResponse = nextAuthMiddleware(request);
// console.log("nextAuthResponse", nextAuthResponse);
// if (nextAuthResponse) {
// // nextAuthResponse.then((res) => {
// // console.log("res", res);
// // if (res.status === 307) {
// // return NextResponse.redirect(
// // new URL(`/${locale}`, request.url)
// // );
// // }
// // });
// // console.log("nextAuthResponse", nextAuthResponse);
// // return NextResponse.next();
// return nextAuthResponse;
// }
// }
// return NextResponse.next();
// }
Describe the bug
We can navigate to pages like the dashboard without logging in.
A clear and concise description of what the bug is.
To Reproduce
Steps to reproduce the behavior:
Do not login
Navigate to /dashboard
Expected behavior
Restrict users who are not logged in to pages except the home page.
A clear and concise description of what you expected to happen.
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Smartphone (please complete the following information):
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: