Skip to content
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

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open

Conversation

VaniaPopovic
Copy link
Contributor

@VaniaPopovic VaniaPopovic commented Mar 22, 2025

Closes #397
Closes #1241

// })
//import { client } from "@acme/auth/middleware";

export default function authMiddleware(_request: NextRequest) {
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image [Should update by itself](https://www.better-auth.com/docs/concepts/session-management)

Copy link
Member

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

Copy link

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.

Copy link
Member

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?

Copy link

@Bekacru Bekacru Mar 23, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: make packages pure and only validate env's in apps
3 participants