Oauth in GoogleAddon

We are using better auth for a web app and a google addon so in web app we can use cookie based oauth login but in addon we can't, so we were trying to use bearer plugin but we are not able to get the 'set-auth-token' on onSuccess handler, i have tried onResponse handler also.

Also i don't know if bearer plugin is good fit for the google addon because it also sets the cookie.

What can we do in this case?
Solution
so when you use social logins we can't set cookies cause it returns back to your back with redirect headers. What you should do is issue send the token as a part of redirect url
export const auth = betterAuth({
  hooks: {
    after: createAuthMiddleware(async(ctx)=>{
        const session = ctx.context.newSession
        if(ctx.path === "/callback/:id" && session){
           const location = ctx.context.responseHeaders.get("location");
           const newLocation = `${location}?token=${session.session.token}`
          ctx.setHeader("location", newLocation)
        }
    })
  }
})
Was this page helpful?