File tree Expand file tree Collapse file tree 3 files changed +7
-84
lines changed
docs/content/docs/plugins
packages/better-auth/src/plugins/multi-session Expand file tree Collapse file tree 3 files changed +7
-84
lines changed Original file line number Diff line number Diff line change @@ -102,15 +102,12 @@ type revokeDeviceSession = {
102102
103103When 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
109107You 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"
112110import { betterAuth } from " better-auth"
113- import { multiSession } from " better-auth/plugins"
114111
115112export 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+ ```
Original file line number Diff line number Diff line change 11import type { BetterAuthClientPlugin } from "@better-auth/core" ;
2- import type { DBFieldAttribute } from "@better-auth/core/db" ;
32import type { multiSession } from "." ;
43import { MULTI_SESSION_ERROR_CODES } from "./error-codes" ;
54
65export * 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 ) {
Original file line number Diff line number Diff line change 33 createAuthEndpoint ,
44 createAuthMiddleware ,
55} from "@better-auth/core/api" ;
6+ import { defineErrorCodes } from "@better-auth/core/utils" ;
67import * as z from "zod" ;
78import { APIError , sessionMiddleware } from "../../api" ;
89import {
@@ -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
2829const setActiveSessionBodySchema = z . object ( {
2930 sessionToken : z . string ( ) . meta ( {
You can’t perform that action at this time.
0 commit comments