Hi, I'm having a few issues with setting this up the way that I want it to but I may be approaching it from the wrong way. I am using another application that I want users to be able to single click sign on into but it is not an Idp or oauth provider. Instead it providers a token in the URL that I can decrypt.
The current imagined workflow is as follows: 1. User clicks button 2. Gets sent to
/api/auth/test/sso
/api/auth/test/sso
3. Create a new plugin that creates a new auth endpoint to decrypt it, create a new user if doesnt exists. 4. Redirect the user to the authenticated
/dashboard
/dashboard
page.
I have created a very simple poc which assumes that all the verification is complete.
import { BetterAuthPlugin, createAuthEndpoint } from "better-auth/plugins";export const tutorcruncherPlugin = () => { return { id: "test", endpoints: { sso: createAuthEndpoint( "/test/sso", { method: "GET", }, async (ctx) => { // Verify stuff - assume that it passes // this is a sample user that I added for testing. const user = await ctx.context.internalAdapter.findUserById( "Bvptc4rkZplmGgzFmx4DylRqVgJbjjIv", ); const session = await ctx.context.internalAdapter.createSession( "Bvptc4rkZplmGgzFmx4DylRqVgJbjjIv", ctx.request, ); ctx.context.setNewSession({ session: session, user: user!, }); return ctx.redirect("/dashboard"); }, ), }, } satisfies BetterAuthPlugin;};
import { BetterAuthPlugin, createAuthEndpoint } from "better-auth/plugins";export const tutorcruncherPlugin = () => { return { id: "test", endpoints: { sso: createAuthEndpoint( "/test/sso", { method: "GET", }, async (ctx) => { // Verify stuff - assume that it passes // this is a sample user that I added for testing. const user = await ctx.context.internalAdapter.findUserById( "Bvptc4rkZplmGgzFmx4DylRqVgJbjjIv", ); const session = await ctx.context.internalAdapter.createSession( "Bvptc4rkZplmGgzFmx4DylRqVgJbjjIv", ctx.request, ); ctx.context.setNewSession({ session: session, user: user!, }); return ctx.redirect("/dashboard"); }, ), }, } satisfies BetterAuthPlugin;};
The above code does not add the cookies into the browser and does not set them either. I have added the