Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

authentication issue #6

Open
ivaibhavraheja opened this issue Jun 28, 2024 · 3 comments
Open

authentication issue #6

ivaibhavraheja opened this issue Jun 28, 2024 · 3 comments

Comments

@ivaibhavraheja
Copy link

the clerk middleware code is not working. I have written the updated middleware code even that is also not working

@deepthiiii4
Copy link

deepthiiii4 commented Sep 1, 2024

import { clerkMiddleware } from '@clerk/nextjs/server';

export default clerkMiddleware({
// Optionally, you can include a list of public routes
// publicRoutes: ['/sign-in', '/public-page'],
});

export const config = {
matcher: [
'/((?!.\..|_next).)', // Exclude static files and Next.js internal paths
'/', // Include the homepage
'/(api|trpc)(.
)' // Include API routes
],
};
use this instead

@ghost
Copy link

ghost commented Nov 6, 2024

It didn't work . I was getting this error and i wrapped the ClerkProvider in that dynamic wrapper

Error: Clerk: useAuth() called in static mode, wrap this component in <ClerkProvider dynamic> to make auth data available during server-side rendering.
    at usePromisifiedAuth (/Users/monarchcoprs/Desktop/Whatsapp-Clone/whatsapp-clone/.next/server/chunks/ssr/node_modules_bae3ec._.js:22898:19)
    at useAuthFromClerk (/Users/monarchcoprs/Desktop/Whatsapp-Clone/whatsapp-clone/.next/server/chunks/ssr/node_modules_bae3ec._.js:5645:56)
    at ConvexProviderWithAuth (/Users/monarchcoprs/Desktop/Whatsapp-Clone/whatsapp-clone/.next/server/chunks/ssr/node_modules_bae3ec._.js:5458:62)
digest: "784848838"

@ghost
Copy link

ghost commented Nov 7, 2024

This is the updated code. It works well with it.

import { clerkMiddleware, createRouteMatcher } from '@clerk/nextjs/server'

const isProtectedRoute = createRouteMatcher(['/(.*)'])

export default clerkMiddleware(async (auth, req) => {
    const { userId, redirectToSignIn } = await auth()

    if (!userId && isProtectedRoute(req)) {
        // Add custom logic to run before redirecting

        return redirectToSignIn()
    }
})

export const config = {
    matcher: [
        // Skip Next.js internals and all static files, unless found in search params
        '/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)',
        // Always run for API routes
        '/(api|trpc)(.*)',
    ],
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants