SaraS
Convex Communityโ€ข5mo agoโ€ข
2 replies
Sara

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)(.*)",
]
};

do i do double auth and add an account per user, and see if they have authorized tokens?
Convex allows third-party app developers to manage a user's projects on their
OAuth Applications | Convex Developer Hub
Was this page helpful?