add auth anonymous plugin

This commit is contained in:
2026-02-24 09:09:08 +01:00
parent dd44f053f9
commit 27d3cd364e
3 changed files with 26 additions and 11 deletions

View File

@@ -1,3 +1,6 @@
import { createAuthClient } from "better-auth/react";
import { anonymousClient } from "better-auth/client/plugins";
export const authClient = createAuthClient({});
export const authClient = createAuthClient({
plugins: [anonymousClient()],
});

View File

@@ -2,6 +2,7 @@ import { db } from "@zendegi/db";
import * as schema from "@zendegi/db/schema/auth";
import { env } from "@zendegi/env/server";
import { betterAuth } from "better-auth";
import { anonymous } from "better-auth/plugins";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { tanstackStartCookies } from "better-auth/tanstack-start";
@@ -15,7 +16,7 @@ export const auth = betterAuth({
emailAndPassword: {
enabled: true,
},
plugins: [tanstackStartCookies()],
plugins: [tanstackStartCookies(), anonymous()],
advanced: {
database: {
generateId: "uuid",

View File

@@ -16,11 +16,14 @@ export const user = pgTable("user", {
email: text("email").notNull().unique(),
emailVerified: boolean("email_verified").default(false).notNull(),
image: text("image"),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at")
createdAt: timestamp("created_at", { withTimezone: true })
.defaultNow()
.notNull(),
updatedAt: timestamp("updated_at", { withTimezone: true })
.defaultNow()
.$onUpdate(() => /* @__PURE__ */ new Date())
.notNull(),
isAnonymous: boolean("is_anonymous").default(false),
});
export const session = pgTable(
@@ -29,10 +32,12 @@ export const session = pgTable(
id: uuid("id")
.default(sql`pg_catalog.gen_random_uuid()`)
.primaryKey(),
expiresAt: timestamp("expires_at").notNull(),
expiresAt: timestamp("expires_at", { withTimezone: true }).notNull(),
token: text("token").notNull().unique(),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at")
createdAt: timestamp("created_at", { withTimezone: true })
.defaultNow()
.notNull(),
updatedAt: timestamp("updated_at", { withTimezone: true })
.$onUpdate(() => /* @__PURE__ */ new Date())
.notNull(),
ipAddress: text("ip_address"),
@@ -58,12 +63,18 @@ export const account = pgTable(
accessToken: text("access_token"),
refreshToken: text("refresh_token"),
idToken: text("id_token"),
accessTokenExpiresAt: timestamp("access_token_expires_at"),
refreshTokenExpiresAt: timestamp("refresh_token_expires_at"),
accessTokenExpiresAt: timestamp("access_token_expires_at", {
withTimezone: true,
}),
refreshTokenExpiresAt: timestamp("refresh_token_expires_at", {
withTimezone: true,
}),
scope: text("scope"),
password: text("password"),
createdAt: timestamp("created_at").defaultNow().notNull(),
updatedAt: timestamp("updated_at")
createdAt: timestamp("created_at", { withTimezone: true })
.defaultNow()
.notNull(),
updatedAt: timestamp("updated_at", { withTimezone: true })
.$onUpdate(() => /* @__PURE__ */ new Date())
.notNull(),
},