[GH-ISSUE #2694] The type of SDK is missing. #9306

Closed
opened 2026-04-13 04:44:08 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @TinsFox on GitHub (May 18, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/2694

// client config
import { adminClient } from "better-auth/client/plugins";
import { username } from "better-auth/plugins/username";
import { createAuthClient } from "better-auth/react";
import { env } from "~/env";

export const authClient = createAuthClient({
	baseURL: env.VITE_APP_URL,
	plugins: [adminClient(), username()],
});

export const { signOut, signIn, signUp, useSession } = createAuthClient();
export type Session = typeof authClient.$Infer.Session;
// server config
import { db } from "@/db";
import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { admin, openAPI, username } from "better-auth/plugins";

import { env } from "cloudflare:workers";
import * as authSchema from "../../auth-schema";
import { resend } from "./email/resend";
import { reactResetPasswordEmail } from "./email/rest-password";
const from = env.BETTER_AUTH_EMAIL;

export const auth = betterAuth({
	plugins: [username(), admin(), openAPI()],
	database: drizzleAdapter(db, {
		provider: "pg",
		schema: authSchema,
		usePlural: true,
	}),
	emailVerification: {
		async sendVerificationEmail({ user, url }) {
			const res = await resend.emails.send({
				from,
				to: user.email,
				subject: "Verify your email address",
				html: `<a href="${url}">Verify your email address</a>`,
			});
			console.log("email verification", res, user.email);
		},
	},
	emailAndPassword: {
		enabled: true,
		async sendResetPassword({ user, url }) {
			const res = await resend.emails.send({
				from,
				to: user.email,
				subject: "Reset your password",
				react: reactResetPasswordEmail({
					username: user.email,
					resetLink: url,
				}),
			});
			console.log("email reset password", res, user.email);
		},
	},
});

I tried to call useSession to get the data of the current user user

When I use user.data?.user, I found that the type of TypeScript is inconsistent with the actual requested data.

Image Image
Originally created by @TinsFox on GitHub (May 18, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/2694 ```ts // client config import { adminClient } from "better-auth/client/plugins"; import { username } from "better-auth/plugins/username"; import { createAuthClient } from "better-auth/react"; import { env } from "~/env"; export const authClient = createAuthClient({ baseURL: env.VITE_APP_URL, plugins: [adminClient(), username()], }); export const { signOut, signIn, signUp, useSession } = createAuthClient(); export type Session = typeof authClient.$Infer.Session; ``` ```ts // server config import { db } from "@/db"; import { betterAuth } from "better-auth"; import { drizzleAdapter } from "better-auth/adapters/drizzle"; import { admin, openAPI, username } from "better-auth/plugins"; import { env } from "cloudflare:workers"; import * as authSchema from "../../auth-schema"; import { resend } from "./email/resend"; import { reactResetPasswordEmail } from "./email/rest-password"; const from = env.BETTER_AUTH_EMAIL; export const auth = betterAuth({ plugins: [username(), admin(), openAPI()], database: drizzleAdapter(db, { provider: "pg", schema: authSchema, usePlural: true, }), emailVerification: { async sendVerificationEmail({ user, url }) { const res = await resend.emails.send({ from, to: user.email, subject: "Verify your email address", html: `<a href="${url}">Verify your email address</a>`, }); console.log("email verification", res, user.email); }, }, emailAndPassword: { enabled: true, async sendResetPassword({ user, url }) { const res = await resend.emails.send({ from, to: user.email, subject: "Reset your password", react: reactResetPasswordEmail({ username: user.email, resetLink: url, }), }); console.log("email reset password", res, user.email); }, }, }); ``` I tried to call `useSession` to get the data of the current user `user` When I use `user.data?.user`, I found that the type of TypeScript is inconsistent with the actual requested data. <img width="858" alt="Image" src="https://github.com/user-attachments/assets/7ac99726-1ae0-4628-ad77-27620eeab4b0" /> <img width="837" alt="Image" src="https://github.com/user-attachments/assets/01621a2a-c45c-49b4-826d-d0198d121b4a" />
GiteaMirror added the locked label 2026-04-13 04:44:08 -05:00
Author
Owner

@TinsFox commented on GitHub (May 18, 2025):

The type of useSession is missing username displayUsername.

<!-- gh-comment-id:2888830144 --> @TinsFox commented on GitHub (May 18, 2025): The type of useSession is missing `username` `displayUsername`.
Author
Owner
<!-- gh-comment-id:2888837718 --> @TinsFox commented on GitHub (May 18, 2025): https://github.com/better-auth/better-auth/issues/2596#issuecomment-2869038423
Author
Owner

@TinsFox commented on GitHub (May 18, 2025):

#2596 (comment)

const user: {
    id: string;
    name: string;
    email: string;
    emailVerified: boolean;
    createdAt: Date;
    updatedAt: Date;
    image?: string | null | undefined | undefined;
    banned: boolean | null | undefined;
    role?: string | null | undefined;
    banReason?: string | ... 1 more ... | undefined;
    banExpires?: Date | ... 1 more ... | undefined;
} | undefined

This is not the final solution, although there are a few more types, the username displayUsername is still missing.

<!-- gh-comment-id:2888843803 --> @TinsFox commented on GitHub (May 18, 2025): > [#2596 (comment)](https://github.com/better-auth/better-auth/issues/2596#issuecomment-2869038423) ```ts const user: { id: string; name: string; email: string; emailVerified: boolean; createdAt: Date; updatedAt: Date; image?: string | null | undefined | undefined; banned: boolean | null | undefined; role?: string | null | undefined; banReason?: string | ... 1 more ... | undefined; banExpires?: Date | ... 1 more ... | undefined; } | undefined ``` This is not the final solution, although there are a few more types, the username displayUsername is still missing.
Author
Owner

@Bekacru commented on GitHub (Jun 16, 2025):

I think the issue here is you're not properly adding the userNameClient plugin to the client plugins list. username is server plugin. feel free to re-open if that's not the case

<!-- gh-comment-id:2974896472 --> @Bekacru commented on GitHub (Jun 16, 2025): I think the issue here is you're not properly adding the `userNameClient` plugin to the client plugins list. `username` is server plugin. feel free to re-open if that's not the case
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#9306