Sara
Sara•6d ago

Best way to send the cookie response to my convex instance after successful authentication

following here: https://docs.convex.dev/platform-apis/oauth-applications I've implemented successful auth and saved the last access token as a cookie, what's the best way to save it so i can use with convex auth to authenticate users/teams? I know that I can use convex.setAuth(access_token) but not sure if it even worked! I also used the middleware from convex-auth to implement it 😅
const isSignInPage = createRouteMatcher(["/start",]);
const isProtectedRoute = createRouteMatcher(["/"]);

export default convexAuthNextjsMiddleware(async (request, { convexAuth }) => {
const token = (await cookies()).get("convex_access_token")?.value
if(!token && isProtectedRoute(request)){
return nextjsMiddlewareRedirect(request, "/start");
} else if(token && isSignInPage(request)){
return nextjsMiddlewareRedirect(request, "/");
}
});

export const config = {
// The following matcher runs middleware on all routes
// except static assets.
matcher: [
"/((?!api/auth/callback|.*\\..*|_next).*)",
"/",
// "/(api|trpc)(.*)",
]
};
const isSignInPage = createRouteMatcher(["/start",]);
const isProtectedRoute = createRouteMatcher(["/"]);

export default convexAuthNextjsMiddleware(async (request, { convexAuth }) => {
const token = (await cookies()).get("convex_access_token")?.value
if(!token && isProtectedRoute(request)){
return nextjsMiddlewareRedirect(request, "/start");
} else if(token && isSignInPage(request)){
return nextjsMiddlewareRedirect(request, "/");
}
});

export const config = {
// The following matcher runs middleware on all routes
// except static assets.
matcher: [
"/((?!api/auth/callback|.*\\..*|_next).*)",
"/",
// "/(api|trpc)(.*)",
]
};
do i do double auth and add an account per user, and see if they have authorized tokens?
OAuth Applications | Convex Developer Hub
Convex allows third-party app developers to manage a user's projects on their
2 Replies
Convex Bot
Convex Bot•6d ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
erquhart
erquhart•6d ago
The application token isn't an id token, so user authentication would still need to be a separate thing.

Did you find this page helpful?