Skip to content

Commit ec57a73

Browse files
committed
Revert "feat(multi-session): allow to infer additional fields (#6585)"
This reverts commit 137863c.
1 parent 6e5b18e commit ec57a73

File tree

3 files changed

+7
-84
lines changed

3 files changed

+7
-84
lines changed

docs/content/docs/plugins/multi-session.mdx

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,12 @@ type revokeDeviceSession = {
102102
103103
When a user logs out, the plugin will revoke all active sessions for the user. You can do this by calling the existing `signOut` method, which handles revoking all sessions automatically.
104104
105-
## Options
106-
107105
### Max Sessions
108106
109107
You can specify the maximum number of sessions a user can have by passing the `maximumSessions` option to the plugin. By default, the plugin allows 5 sessions per device.
110108
111109
```ts title="auth.ts"
112110
import { betterAuth } from "better-auth"
113-
import { multiSession } from "better-auth/plugins"
114111

115112
export const auth = betterAuth({
116113
plugins: [
@@ -119,59 +116,4 @@ export const auth = betterAuth({
119116
})
120117
]
121118
})
122-
```
123-
124-
### Additional Fields
125-
126-
You can infer additional fields for the `user` and `session` schema by passing the `schema` option to both plugins.
127-
128-
<Callout type="warning">
129-
Note that this only affects type inference and does not modify the actual database schema.
130-
Make sure that you [extend the core schema](/docs/concepts/database#extending-core-schema) accordingly.
131-
</Callout>
132-
133-
```ts title="auth.ts"
134-
import { betterAuth } from "better-auth"
135-
import { multiSession } from "better-auth/plugins"
136-
137-
export const auth = betterAuth({
138-
plugins: [
139-
multiSession({
140-
schema: {
141-
user: {
142-
additionalFields: {
143-
lang: {
144-
type: "string",
145-
required: false,
146-
defaultValue: "en"
147-
}
148-
}
149-
}
150-
}
151-
})
152-
]
153-
})
154-
```
155-
156-
```ts title="auth-client.ts"
157-
import { createAuthClient } from "better-auth/client"
158-
import { multiSessionClient } from "better-auth/client/plugins"
159-
160-
export const authClient = createAuthClient({
161-
plugins: [
162-
multiSessionClient({
163-
schema: {
164-
user: {
165-
additionalFields: {
166-
lang: {
167-
type: "string",
168-
required: false,
169-
defaultValue: "en"
170-
}
171-
}
172-
}
173-
}
174-
})
175-
]
176-
})
177-
```
119+
```

packages/better-auth/src/plugins/multi-session/client.ts

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,13 @@
11
import type { BetterAuthClientPlugin } from "@better-auth/core";
2-
import type { DBFieldAttribute } from "@better-auth/core/db";
32
import type { multiSession } from ".";
43
import { MULTI_SESSION_ERROR_CODES } from "./error-codes";
54

65
export * from "./error-codes";
76

8-
export type MultiSessionClientOptions = {
9-
schema?:
10-
| {
11-
user?:
12-
| {
13-
additionalFields?: Record<string, DBFieldAttribute> | undefined;
14-
}
15-
| undefined;
16-
session?:
17-
| {
18-
additionalFields?: Record<string, DBFieldAttribute> | undefined;
19-
}
20-
| undefined;
21-
}
22-
| undefined;
23-
};
24-
25-
export const multiSessionClient = <O extends MultiSessionClientOptions>(
26-
options?: O | undefined,
27-
) => {
7+
export const multiSessionClient = () => {
288
return {
299
id: "multi-session",
30-
$InferServerPlugin: {} as ReturnType<typeof multiSession<O>>,
10+
$InferServerPlugin: {} as ReturnType<typeof multiSession>,
3111
atomListeners: [
3212
{
3313
matcher(path) {

packages/better-auth/src/plugins/multi-session/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
createAuthEndpoint,
44
createAuthMiddleware,
55
} from "@better-auth/core/api";
6+
import { defineErrorCodes } from "@better-auth/core/utils";
67
import * as z from "zod";
78
import { APIError, sessionMiddleware } from "../../api";
89
import {
@@ -21,9 +22,9 @@ export interface MultiSessionConfig {
2122
maximumSessions?: number | undefined;
2223
}
2324

24-
import { MULTI_SESSION_ERROR_CODES as ERROR_CODES } from "./error-codes";
25-
26-
export { MULTI_SESSION_ERROR_CODES as ERROR_CODES } from "./error-codes";
25+
const ERROR_CODES = defineErrorCodes({
26+
INVALID_SESSION_TOKEN: "Invalid session token",
27+
});
2728

2829
const setActiveSessionBodySchema = z.object({
2930
sessionToken: z.string().meta({

0 commit comments

Comments
 (0)