mirror of
https://github.com/LukeHagar/better-auth.git
synced 2025-12-09 20:27:44 +00:00
docs: add activeOrganizationId on org schema
This commit is contained in:
@@ -18,6 +18,7 @@ import { MysqlDialect } from "kysely";
|
||||
import { createPool } from "mysql2/promise";
|
||||
import { nextCookies } from "better-auth/next-js";
|
||||
import { customSession } from "./auth/plugins/custom-session";
|
||||
import { addAccountToSession } from "./plugin";
|
||||
|
||||
const from = process.env.BETTER_AUTH_EMAIL || "delivered@resend.dev";
|
||||
const to = process.env.TEST_EMAIL || "";
|
||||
@@ -155,6 +156,6 @@ export const auth = betterAuth({
|
||||
oneTap(),
|
||||
oAuthProxy(),
|
||||
nextCookies(),
|
||||
customSession(),
|
||||
addAccountToSession,
|
||||
],
|
||||
});
|
||||
|
||||
40
demo/nextjs/lib/plugin.ts
Normal file
40
demo/nextjs/lib/plugin.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import { BetterAuthPlugin } from "better-auth";
|
||||
|
||||
export const addAccountToSession = {
|
||||
id: "add-account-to-session",
|
||||
hooks: {
|
||||
after: [
|
||||
{
|
||||
matcher(context) {
|
||||
return context.path.startsWith("/callback");
|
||||
},
|
||||
async handler(ctx) {
|
||||
const sessionCookie = ctx.responseHeader.get(
|
||||
ctx.context.authCookies.sessionToken.name,
|
||||
);
|
||||
if (!sessionCookie) {
|
||||
return;
|
||||
}
|
||||
const provider = ctx.path.split("/callback")[1];
|
||||
if (!provider) {
|
||||
return;
|
||||
}
|
||||
const sessionId = sessionCookie.split(".")[0];
|
||||
await ctx.context.internalAdapter.updateSession(sessionId, {
|
||||
accountId: provider,
|
||||
});
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
schema: {
|
||||
session: {
|
||||
fields: {
|
||||
accountId: {
|
||||
type: "string",
|
||||
required: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} satisfies BetterAuthPlugin;
|
||||
Reference in New Issue
Block a user