Unable to access login page after deployment?
I can access the index page after deploying to Vercel on https://nform.vercel.app/
But when I try to access https://app.nform.vercel.app/ - I get an SSL error.
However, when testing on localhost ie. app.localhost:3000, I am able to access the page.
What am I missing from my deployment? I checked the guide and I am sure I followed most of the steps.
My middleware file:
import { NextRequest, NextResponse } from "next/server";
export const config = {
matcher: [
/*
* Match all paths except for:
* 1. /api routes
* 2. /_next (Next.js internals)
* 3. /fonts (inside /public)
* 4. /examples (inside /public)
* 5. all root files inside /public (e.g. /favicon.ico)
*/
"/((?!api|_next|fonts|examples|[\\w-]+\\.\\w+).*)",
],
};
export default function middleware(req: NextRequest) {
const url = req.nextUrl;
// Get hostname of request (e.g. demo.vercel.pub, demo.localhost:3000)
const hostname = req.headers.get("host") || "demo.vercel.pub";
// Only for demo purposes - remove this if you want to use your root domain as the landing page
// if (hostname === "vercel.pub" || hostname === "platforms.vercel.app") {
// return NextResponse.redirect("https://demo.vercel.pub");
// }
/* You have to replace ".vercel.pub" with your own domain if you deploy this example under your domain.
You can also use wildcard subdomains on .vercel.app links that are associated with your Vercel team slug
in this case, our team slug is "platformize", thus *.platformize.vercel.app works. Do note that you'll
still need to add "*.platformize.vercel.app" as a wildcard domain on your Vercel dashboard. */
const currentHost =
process.env.NODE_ENV === "production" && process.env.VERCEL === "1"
? hostname
.replace(`.nform.vercel.app`, "")
.replace(`.nform.vercel.app`, "")
: hostname.replace(`.localhost:3000`, "");
console.log(currentHost);
// rewrites for app pages
if (currentHost == "app") {
if (
url.pathname === "/login" &&
(req.cookies.get("next-auth.session-token") ||
req.cookies.get("__Secure-next-auth.session-token"))
) {
url.pathname = "/";
return NextResponse.redirect(url);
}
url.pathname = `/app${url.pathname}`;
return NextResponse.rewrite(url);
}
// rewrite root application to `/home` folder
if (hostname === "localhost:3000" || hostname === "nform.vercel.app") {
url.pathname = `/home${url.pathname}`;
return NextResponse.rewrite(url);
}
// rewrite everything else to `/_sites/[site] dynamic route
url.pathname = `/_sites/${currentHost}${url.pathname}`;
return NextResponse.rewrite(url);
}
I have the same problem.
It seems that you have to enable wildcard domains on Vercel. But I cannot figure out how to do that on [project].vercel.pub domains.
I cannot add *.[projectname].vercel.pub to my domains, it throws an error
Error:"name" does not have access to "*.[project-name].vercel.app" domains.
It is also discussed here : https://github.com/orgs/vercel/discussions/475
Hey! This should be fixed now with the https://github.com/vercel/platforms/pull/221 migration complete!