Confused about Better Auth + Backend Middleware + Auth

Hey, folks

Im using Better Auth for authentication on my server (using Effect-TS). There is a middleware (not in better-auth config), that needs to check 2 scenarios basically:

  1. IF there is a session cookie, which needs to be validated (not idea how), THEN user is authenticated.
  2. IF there isn't a session cookie, then we check Authorization: Bearer ${token} header and validate the JWT with JOSE lib.
Questions

  1. Do I need both bearer() and jwt() plugins enabled in better-auth config?
  2. After user logged in / signed up on the server, will better-auth set a session cookie in headers automatically or do i have to extract it from somewhere and then set it myself? Where do i get this token from? Do I set the session token I received after logging in to the cookie?
  3. What is generally considered a good practice for a middleware that checks the JTW with Bearer (for mobile and curl requests) and cookie token for web requests?
Would greatly appreciate any answers and opinions.
Was this page helpful?