How to log sign-in, sign-out, and errors?
Hi, How can I log user logins, logouts, errors, and other actions in the Better Auth library? I’m using it in a Next.js.
Is there a built-in way to handle logging, or do I need to implement custom event tracking? Thank you
4 Replies
if you are using server components use auth instance,
if you are using client component use authClient instance
Basic Usage | Better Auth
Getting started with Better Auth
So the best way to achieve this is to handle logging manually in server actions? For example, I can use:
I also tried using the after hooks in auth.ts, but it didn’t seem to work. Has anyone successfully implemented logging using these hooks?
So, Better Auth doesn’t have a built-in logging system?
you can use authClient from client components , here is the implementation
additionally you can setup a middleware to only check for the existence of a session cookie to handle redirection.