forked from cartsnitch/cartsnitch
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 146322f51e | |||
| 835aff3522 | |||
| 5588c1b5d8 | |||
| c5ed863ab1 | |||
| 8d0552f73f | |||
| 3a75ee7aee | |||
| 30d670a257 |
@@ -0,0 +1,26 @@
|
|||||||
|
"""Make users.hashed_password nullable.
|
||||||
|
|
||||||
|
Better-Auth inserts users without hashed_password (passwords live in the
|
||||||
|
accounts table). This column is now purely optional.
|
||||||
|
|
||||||
|
Revision ID: 003_make_users_hashed_password_nullable
|
||||||
|
Revises: 002_better_auth_tables
|
||||||
|
Create Date: 2026-03-30
|
||||||
|
"""
|
||||||
|
|
||||||
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
|
||||||
|
revision = "003_make_users_hashed_password_nullable"
|
||||||
|
down_revision = "002_better_auth_tables"
|
||||||
|
branch_labels = None
|
||||||
|
depends_on = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade() -> None:
|
||||||
|
op.alter_column("users", "hashed_password", existing_type=sa.String(255), nullable=True)
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
op.alter_column("users", "hashed_password", existing_type=sa.String(255), nullable=False)
|
||||||
@@ -21,7 +21,7 @@ class User(UUIDPrimaryKeyMixin, TimestampMixin, Base):
|
|||||||
__tablename__ = "users"
|
__tablename__ = "users"
|
||||||
|
|
||||||
email: Mapped[str] = mapped_column(String(255), nullable=False, unique=True)
|
email: Mapped[str] = mapped_column(String(255), nullable=False, unique=True)
|
||||||
hashed_password: Mapped[str] = mapped_column(String(255), nullable=False)
|
hashed_password: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
||||||
display_name: Mapped[str | None] = mapped_column(String(100))
|
display_name: Mapped[str | None] = mapped_column(String(100))
|
||||||
email_verified: Mapped[bool] = mapped_column(Boolean, nullable=False, server_default="false")
|
email_verified: Mapped[bool] = mapped_column(Boolean, nullable=False, server_default="false")
|
||||||
image: Mapped[str | None] = mapped_column(Text, nullable=True)
|
image: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||||
|
|||||||
+29
-1
@@ -1,8 +1,36 @@
|
|||||||
import { createAuthClient } from "better-auth/react"
|
import { createAuthClient } from "better-auth/react"
|
||||||
|
import type { BetterFetchPlugin } from "@better-fetch/fetch"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps 'name' -> 'display_name' in register requests to match the API's RegisterRequest schema.
|
||||||
|
*/
|
||||||
|
const displayNameMapper: BetterFetchPlugin = {
|
||||||
|
id: "display-name-mapper",
|
||||||
|
name: "display-name-mapper",
|
||||||
|
hooks: {
|
||||||
|
onRequest: async (context) => {
|
||||||
|
const url = typeof context.url === "string" ? context.url : context.url.pathname
|
||||||
|
if (
|
||||||
|
url.endsWith("/auth/register") &&
|
||||||
|
context.method === "POST" &&
|
||||||
|
context.body &&
|
||||||
|
"name" in context.body
|
||||||
|
) {
|
||||||
|
context.body = {
|
||||||
|
...context.body,
|
||||||
|
display_name: context.body.name as string,
|
||||||
|
name: undefined,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return context
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
export const authClient = createAuthClient({
|
export const authClient = createAuthClient({
|
||||||
baseURL: import.meta.env.VITE_AUTH_URL ?? "http://localhost:3001",
|
baseURL: import.meta.env.VITE_AUTH_URL || "",
|
||||||
basePath: "/auth",
|
basePath: "/auth",
|
||||||
|
fetchPlugins: [displayNameMapper],
|
||||||
})
|
})
|
||||||
|
|
||||||
export const { useSession, signIn, signUp, signOut } = authClient
|
export const { useSession, signIn, signUp, signOut } = authClient
|
||||||
|
|||||||
Reference in New Issue
Block a user