How can I run a hook after the Google OAuth flow?

Hey, I'm in the process of migrating my previous custom auth logic to better-auth. I'm using better-auth on my Hono backend. I need to execute logic after the user completes the Google OAuth flow, I need to recreate a Postgres materialized view adding the newly create user. Previously I just had this logic in the handler itself but now I'm not sure where to add this logic. I'm trying to add this logic to a hook like so:
hooks: {
after: createAuthMiddleware(async (ctx) => {
if (ctx.path.includes("/callback/google")) {
await db.refreshMaterializedView(usersView);
}
}),

hooks: {
after: createAuthMiddleware(async (ctx) => {
if (ctx.path.includes("/callback/google")) {
await db.refreshMaterializedView(usersView);
}
}),

}, but this for some reason is never running. What's the proper way to add some logic to a step of the auth flow?
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?