wess
wess
CCConvex Community
Created by wess on 12/19/2024 in #support-community
Should I use `users` table or `profiles`?
Should I use users table from Convex Auth for storing additional user data, or should I better create profiles table and store it there, not touching the users table? Which one is considered a best practice for Convex Auth?
15 replies
CCConvex Community
Created by wess on 12/16/2024 in #support-community
debouncing
hey! i have a text input and based on its value i need to query the database? right now as soon as i type something it starts to query and is being super reactive. which is good, but at the same time "isn't it putting too much pressure on db"? and hence increasing the total costs for me? should i implement a debouncing on the client side for that? if yes -- then whats is the best way to do that? because its returning immediately results for previous debounced value -- which is wrong and staying like that for some time until the next debounced value appears
13 replies
CCConvex Community
Created by wess on 12/14/2024 in #support-community
Auth not working properly in Nextjs
hey guys what could be the reason that convex auth is not working properly on my nextjs app? setup everything as on the tutorial but after login, i dont get redirected and even if i manually go to protected route, i still get redirected back to /login page, and isAuthenticated is always loggin false
import {
convexAuthNextjsMiddleware,
createRouteMatcher,
nextjsMiddlewareRedirect,
} from '@convex-dev/auth/nextjs/server'

const PUBLIC_ROUTES = ['/login', '/signup', '/forgot-password', '/public', '/about']
const PROTECTED_ROUTES = ['/product(.*)', '/dashboard(.*)', '/user(.*)', '/']

const isPublicRoute = createRouteMatcher(PUBLIC_ROUTES)
const isProtectedRoute = createRouteMatcher(PROTECTED_ROUTES)

export default convexAuthNextjsMiddleware(async (request, { convexAuth }) => {
const isAuthenticated = await convexAuth.isAuthenticated()
console.log('isAuthenticated', isAuthenticated)

const url = new URL(request.url)

try {
if (url.pathname === '/login' && isAuthenticated) {
return nextjsMiddlewareRedirect(request, '/')
}

if (isProtectedRoute(request) && !isAuthenticated) {
return Response.redirect(new URL(`/login?returnTo=${url.pathname}`, request.url))
}

if (isPublicRoute(request)) {
return
}

return
} catch (error) {
console.error('Middleware error:', error)
return nextjsMiddlewareRedirect(request, '/error')
}
})

export const config = {
matcher: ['/((?!api|_next/static|_next/image|favicon.ico|public).*)'],
}
import {
convexAuthNextjsMiddleware,
createRouteMatcher,
nextjsMiddlewareRedirect,
} from '@convex-dev/auth/nextjs/server'

const PUBLIC_ROUTES = ['/login', '/signup', '/forgot-password', '/public', '/about']
const PROTECTED_ROUTES = ['/product(.*)', '/dashboard(.*)', '/user(.*)', '/']

const isPublicRoute = createRouteMatcher(PUBLIC_ROUTES)
const isProtectedRoute = createRouteMatcher(PROTECTED_ROUTES)

export default convexAuthNextjsMiddleware(async (request, { convexAuth }) => {
const isAuthenticated = await convexAuth.isAuthenticated()
console.log('isAuthenticated', isAuthenticated)

const url = new URL(request.url)

try {
if (url.pathname === '/login' && isAuthenticated) {
return nextjsMiddlewareRedirect(request, '/')
}

if (isProtectedRoute(request) && !isAuthenticated) {
return Response.redirect(new URL(`/login?returnTo=${url.pathname}`, request.url))
}

if (isPublicRoute(request)) {
return
}

return
} catch (error) {
console.error('Middleware error:', error)
return nextjsMiddlewareRedirect(request, '/error')
}
})

export const config = {
matcher: ['/((?!api|_next/static|_next/image|favicon.ico|public).*)'],
}
19 replies