trippester
Redirect to Localhost?
That wasn't the issue. It's not hitting the API to execute the login/logout function. It gets the url from the env fine. Also, my page loads are 4x longer now on railway. 5.9seconds vs 1.2 before. I wanted to go server-based since the next feature requires sockets...
26 replies
Redirect to Localhost?
Why would it ever go to localhost? I can't figure this out. I've updated the code but to no avail.
import { createSupabaseRouteHandlerClient } from '@/lib/utils/getServerSupabaseClient';
import { NextResponse } from 'next/server';
export const dynamic = 'force-dynamic';
export async function POST(request: Request) {
const requestUrl = new URL(request.url);
const formData = await request.formData();
const email = String(formData.get('email'));
const password = String(formData.get('password'));
const supabase = createSupabaseRouteHandlerClient();
const { error } = await supabase.auth.signInWithPassword({
email,
password,
});
// Use BASE_URL if set, otherwise fallback to requestUrl.origin
const baseUrl = process.env.BASE_URL || requestUrl.origin;
if (error) {
return NextResponse.redirect(
${baseUrl}/login?error=Could not authenticate user
, {
// a 301 status is required to redirect from a POST to a GET route
status: 301,
});
}
return NextResponse.redirect(baseUrl, {
// a 301 status is required to redirect from a POST to a GET route
status: 301,
});
}
Set the env on railway. Will not correctly direct the user. I know there is a workaround I am missing but I like the idea of the server having this protection built in as a patch if needed.26 replies
Redirect to Localhost?
I did have
export const dynamic = 'force-dynamic';
due for vercel to work...
import { redirect } from 'next/navigation';
import Header from '@/components/Header';
import NavBar from '@/components/Navbar';
import ClassBanner from '@/components/ClassBanner';
import { getCurrentUser } from '@/lib/utils/getCurrentUser';
// Vercel fails to build if this is not exported
export const dynamic = 'force-dynamic';
export default async function MainLayout({ children }: { children: React.ReactNode }) {
const currentUser = await getCurrentUser();
if (!currentUser) {
redirect('/login');
}
return (
<div className="w-full h-full bg-[#1B2026]">
<div className="">
<ClassBanner />
<Header user={currentUser} />
<NavBar />
</div>
<div className="w-full h-full pt-[95px] md:pt-[105px]">{children}</div>
</div>
);
}
26 replies