-
-
Notifications
You must be signed in to change notification settings - Fork 448
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
Feat: better-auth #1321
base: main
Are you sure you want to change the base?
Feat: better-auth #1321
Conversation
// }) | ||
//import { client } from "@acme/auth/middleware"; | ||
|
||
export default function authMiddleware(_request: NextRequest) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't you need something to handle session refreshing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure how that works in next.js where you can only set headers in server actions and middleware though?
when a user is browsing pages they won't be refreshing their session, right
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The session is refreshed whenever /get-session is called, whether it's from a server action, middleware, or from the client. Only server component calls won't be able to do this because they can't set cookies. But, the session in the database will still be refreshed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea so I'm right in assuming that if we don't have a middleware in this repo, the session wouldn't be refreshed since we're only making authApi calls from RSCs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes. I'm assuming when there's a trpc call where getSession
is called to check for the session, it'll be refreshed. But we can also have the middleware. And, if it can only support Next.js 15.2 and above, we can switch to auth.api.getSession
. Which will remove the API call and uses cookie caching, to prevent db calls until the cache is invalid
https://www.better-auth.com/docs/integrations/next#for-nextjs-release-1520-and-above
Closes #397
Closes #1241