mirror of
https://github.com/LukeHagar/better-auth.git
synced 2025-12-06 12:27:44 +00:00
chore: move types to
This commit is contained in:
@@ -28,3 +28,5 @@ export const {
|
||||
useListOrganizations,
|
||||
useActiveOrganization,
|
||||
} = client;
|
||||
|
||||
client.$Infer;
|
||||
|
||||
@@ -196,6 +196,23 @@ export const contents: Content[] = [
|
||||
</svg>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: "Typescript",
|
||||
href: "/docs/concepts/typescript",
|
||||
icon: () => (
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="1em"
|
||||
height="1em"
|
||||
viewBox="0 0 128 128"
|
||||
>
|
||||
<path
|
||||
className="fill-foreground"
|
||||
d="M2 63.91v62.5h125v-125H2zm100.73-5a15.56 15.56 0 0 1 7.82 4.5a20.6 20.6 0 0 1 3 4c0 .16-5.4 3.81-8.69 5.85c-.12.08-.6-.44-1.13-1.23a7.09 7.09 0 0 0-5.87-3.53c-3.79-.26-6.23 1.73-6.21 5a4.6 4.6 0 0 0 .54 2.34c.83 1.73 2.38 2.76 7.24 4.86c8.95 3.85 12.78 6.39 15.16 10c2.66 4 3.25 10.46 1.45 15.24c-2 5.2-6.9 8.73-13.83 9.9a38.3 38.3 0 0 1-9.52-.1A23 23 0 0 1 80 109.19c-1.15-1.27-3.39-4.58-3.25-4.82a9 9 0 0 1 1.15-.73l4.6-2.64l3.59-2.08l.75 1.11a16.8 16.8 0 0 0 4.74 4.54c4 2.1 9.46 1.81 12.16-.62a5.43 5.43 0 0 0 .69-6.92c-1-1.39-3-2.56-8.59-5c-6.45-2.78-9.23-4.5-11.77-7.24a16.5 16.5 0 0 1-3.43-6.25a25 25 0 0 1-.22-8c1.33-6.23 6-10.58 12.82-11.87a31.7 31.7 0 0 1 9.49.26zm-29.34 5.24v5.12H57.16v46.23H45.65V69.26H29.38v-5a49 49 0 0 1 .14-5.16c.06-.08 10-.12 22-.1h21.81z"
|
||||
></path>
|
||||
</svg>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: "User & Accounts",
|
||||
href: "/docs/concepts/user-accounts",
|
||||
@@ -228,7 +245,7 @@ export const contents: Content[] = [
|
||||
clipRule="evenodd"
|
||||
></path>
|
||||
<path
|
||||
fill="currentColor"
|
||||
className="fill-foreground"
|
||||
d="M18.25 3.151c-.62.073-1.23.18-1.75.336a8 8 0 0 0-.75.27v3.182l.75-.356l.008-.005a1.1 1.1 0 0 1 .492-.13q.072 0 .138.01c.175.029.315.1.354.12l.009.005l.75.356V3.15"
|
||||
></path>
|
||||
</svg>
|
||||
@@ -244,7 +261,7 @@ export const contents: Content[] = [
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<path
|
||||
fill="currentColor"
|
||||
className="fill-foreground"
|
||||
fillRule="evenodd"
|
||||
d="M10 4h4c3.771 0 5.657 0 6.828 1.172C22 6.343 22 8.229 22 12c0 3.771 0 5.657-1.172 6.828C19.657 20 17.771 20 14 20h-4c-3.771 0-5.657 0-6.828-1.172C2 17.657 2 15.771 2 12c0-3.771 0-5.657 1.172-6.828C4.343 4 6.229 4 10 4m3.25 5a.75.75 0 0 1 .75-.75h5a.75.75 0 0 1 0 1.5h-5a.75.75 0 0 1-.75-.75m1 3a.75.75 0 0 1 .75-.75h4a.75.75 0 0 1 0 1.5h-4a.75.75 0 0 1-.75-.75m1 3a.75.75 0 0 1 .75-.75h3a.75.75 0 0 1 0 1.5h-3a.75.75 0 0 1-.75-.75M11 9a2 2 0 1 1-4 0a2 2 0 0 1 4 0m-2 8c4 0 4-.895 4-2s-1.79-2-4-2s-4 .895-4 2s0 2 4 2"
|
||||
clipRule="evenodd"
|
||||
|
||||
35
docs/content/docs/concepts/typescript.mdx
Normal file
35
docs/content/docs/concepts/typescript.mdx
Normal file
@@ -0,0 +1,35 @@
|
||||
---
|
||||
title: Typescript
|
||||
description: Better auth typescript integration
|
||||
---
|
||||
|
||||
Better Auth is designed to be type-safe. Both the client and server are built with TypeScript, allowing you to easily infer types.
|
||||
|
||||
## Infering Types
|
||||
|
||||
Both the client SDK and the server offer types that can be inferred using the `$Infer` property. Plugins can extend base types like `User` and `Session`, and you can use `$Infer` to infer these types. Additionally, plugins can provide extra types that can also be inferred through `$Infer`.
|
||||
|
||||
```ts title="client.ts" twoslash
|
||||
import { createAuthClient } from "better-auth/client"
|
||||
|
||||
const client = createAuthClient()
|
||||
|
||||
export type Session = typeof client.$Infer.Session
|
||||
```
|
||||
|
||||
The `Session` type includes both `session` and `user` properties. The user property represents the user object type, and the `session` property represents the `session` object type.
|
||||
|
||||
You can also infer types on the server side.
|
||||
|
||||
```ts title="auth.ts" twoslash
|
||||
import { betterAuth } from "better-auth"
|
||||
|
||||
export const auth = await betterAuth({
|
||||
database: {
|
||||
provider: "sqlite",
|
||||
url: "./db.sqlite",
|
||||
}
|
||||
})
|
||||
|
||||
type Session = typeof auth.$Infer.Session
|
||||
```
|
||||
@@ -46,8 +46,8 @@ export const betterAuth = <O extends BetterAuthOptions>(options: O) => {
|
||||
},
|
||||
api: api as InferAPI<typeof api>,
|
||||
options: authContext.options as O,
|
||||
$infer: {} as {
|
||||
session: {
|
||||
$Infer: {} as {
|
||||
Session: {
|
||||
session: Prettify<InferSession<O>>;
|
||||
user: Prettify<InferUser<O>>;
|
||||
};
|
||||
|
||||
4
todo.md
4
todo.md
@@ -11,13 +11,13 @@
|
||||
[ ] fix bun problem
|
||||
[x] fix the issue with the client triggers not working fot 2 consecutive calls
|
||||
[ ] add a way to specify on the client to use the base path as the whole path
|
||||
[ ] implement magic links
|
||||
[x] implement magic links
|
||||
|
||||
|
||||
## Docs
|
||||
[x] specify everywhere `auth` should be exported
|
||||
[-] add a note about better-sqlite3 requiring to be added to webpack externals or find alternative that doesn't require it
|
||||
[ ] add a section about updating user and changing password
|
||||
[x] add a section about updating user and changing password
|
||||
[ ] mention how users can get user and session types
|
||||
[ ] add a doc about account linking
|
||||
[ ] remove the section about using useSession in next with initialValue
|
||||
|
||||
Reference in New Issue
Block a user