:question: How to Log In Programmatically as Any User (Super Admin Impersonation Use Case)

Hi Better Auth team 👋 I'm trying to build a super admin panel where I can manage multiple organizations and their users. I already fetch the list of users and want to support a "Login As" feature — where I click a button and get logged in as that user (without needing their password). What I'm Doing: * I can fetch the user's info from the org * I generate a session manually in the DB (using the same structure as Better Auth’s session table) * I open a link like /impersonate?token=... in the CMS app * On the server, I check the token and insert a session into the session table * I set the cookie better-auth.session_token manually The Problem: Even after inserting the session and setting the cookie, Better Auth doesn’t recognize the session — it returns null in the auth middleware. Question: 👉 What’s the correct or recommended way to programmatically log in as a user (impersonation use case)? How can I create a valid session Better Auth will accept? Thanks in advance 🙏
1 Reply
Jackson Kasi
Jackson KasiOP•3mo ago
just update. using magic link plugin i solved!

Did you find this page helpful?