Update development script and add error handling in authentication middleware
The "dev" script in the package.json for apps/web updated to include a "--turbo" flag. Moreover, enhanced error handling logic is added to the authentication
This commit is contained in:
@@ -115,7 +115,14 @@ function getPatterns() {
|
|||||||
pattern: new URLPattern({ pathname: '/auth*' }),
|
pattern: new URLPattern({ pathname: '/auth*' }),
|
||||||
handler: async (req: NextRequest, res: NextResponse) => {
|
handler: async (req: NextRequest, res: NextResponse) => {
|
||||||
const supabase = createMiddlewareClient(req, res);
|
const supabase = createMiddlewareClient(req, res);
|
||||||
const { data: user } = await supabase.auth.getUser();
|
const { data: user, error } = await supabase.auth.getUser();
|
||||||
|
|
||||||
|
// the user is logged out, so we don't need to do anything
|
||||||
|
if (error) {
|
||||||
|
await supabase.auth.signOut();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// check if we need to verify MFA (user is authenticated but needs to verify MFA)
|
// check if we need to verify MFA (user is authenticated but needs to verify MFA)
|
||||||
const isVerifyMfa = req.nextUrl.pathname === pathsConfig.auth.verifyMfa;
|
const isVerifyMfa = req.nextUrl.pathname === pathsConfig.auth.verifyMfa;
|
||||||
@@ -137,6 +144,9 @@ function getPatterns() {
|
|||||||
const origin = req.nextUrl.origin;
|
const origin = req.nextUrl.origin;
|
||||||
const next = req.nextUrl.pathname;
|
const next = req.nextUrl.pathname;
|
||||||
|
|
||||||
|
console.log('home:user', user);
|
||||||
|
console.log('home:error', error);
|
||||||
|
|
||||||
// If user is not logged in, redirect to sign in page.
|
// If user is not logged in, redirect to sign in page.
|
||||||
if (!user || error) {
|
if (!user || error) {
|
||||||
const signIn = pathsConfig.auth.signIn;
|
const signIn = pathsConfig.auth.signIn;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
"analyze": "ANALYZE=true pnpm run build",
|
"analyze": "ANALYZE=true pnpm run build",
|
||||||
"build": "pnpm with-env next build",
|
"build": "pnpm with-env next build",
|
||||||
"clean": "git clean -xdf .next .turbo node_modules",
|
"clean": "git clean -xdf .next .turbo node_modules",
|
||||||
"dev": "pnpm with-env next dev",
|
"dev": "pnpm with-env next dev --turbo",
|
||||||
"lint": "next lint",
|
"lint": "next lint",
|
||||||
"format": "prettier --check \"**/*.{js,cjs,mjs,ts,tsx,md,json}\"",
|
"format": "prettier --check \"**/*.{js,cjs,mjs,ts,tsx,md,json}\"",
|
||||||
"start": "pnpm with-env next start",
|
"start": "pnpm with-env next start",
|
||||||
|
|||||||
Reference in New Issue
Block a user