Application error: Client Side Exception when clicking the Link on the Not Found Page.
Unanswered
Jenn posted this in #help-forum
JennOP
Hello, I encountered a problem where if I put a Link on the not found page, clicking the link will show this on the screen: Application error: a client-side exception has occurred (see the browser console for more information). This error only shows up for those unauthenticated users. No error shows for those who are authenticated. Any idea what is wrong with the application?
What should I look into when there is an error like this?
My
Login/route.ts:
What should I look into when there is an error like this?
My
middleware.ts: export async function middleware(req: NextRequest) {
const res = NextResponse.next()
const supabase = createMiddlewareClient({ req, res })
const {
data: { user },
} = await supabase.auth.getUser()
// if user is not signed in and the current path is not /login redirect the user to /
if (!user && req.nextUrl.pathname !== '/login') {
return NextResponse.redirect(new URL('/', req.url))
}
return res
}
export const config = {
matcher: ['/water_station:path', '/waterTypes:path',],
}Login/route.ts:
import { createRouteHandlerClient } from '@supabase/auth-helpers-nextjs'
import { cookies } from 'next/headers'
import { NextResponse } from 'next/server'
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 cookieStore = cookies()
const supabase = createRouteHandlerClient({ cookies: () => cookieStore })
await supabase.auth.signInWithPassword({
email,
password,
})
return NextResponse.redirect(requestUrl.origin, {
status: 301,
})
}