@delmaredigital/payload-better-auth 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +734 -0
- package/dist/adapter/index.d.mts +70 -0
- package/dist/adapter/index.d.ts +70 -0
- package/dist/adapter/index.js +368 -0
- package/dist/adapter/index.js.map +1 -0
- package/dist/adapter/index.mjs +366 -0
- package/dist/adapter/index.mjs.map +1 -0
- package/dist/client.d.mts +1 -0
- package/dist/client.d.ts +1 -0
- package/dist/client.js +12 -0
- package/dist/client.js.map +1 -0
- package/dist/client.mjs +3 -0
- package/dist/client.mjs.map +1 -0
- package/dist/index.d.mts +120 -0
- package/dist/index.d.ts +120 -0
- package/dist/index.js +611 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +603 -0
- package/dist/index.mjs.map +1 -0
- package/dist/plugin/index.d.mts +78 -0
- package/dist/plugin/index.d.ts +78 -0
- package/dist/plugin/index.js +86 -0
- package/dist/plugin/index.js.map +1 -0
- package/dist/plugin/index.mjs +82 -0
- package/dist/plugin/index.mjs.map +1 -0
- package/package.json +73 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
export { PayloadAdapterConfig, payloadAdapter } from './adapter/index.js';
|
|
2
|
+
import { CollectionConfig, Plugin, BasePayload } from 'payload';
|
|
3
|
+
import { BetterAuthOptions } from 'better-auth';
|
|
4
|
+
export { Auth, BetterAuthPluginOptions, BetterAuthStrategyOptions, CreateAuthFunction, PayloadWithAuth, betterAuthStrategy, createBetterAuthPlugin, resetAuthInstance } from './plugin/index.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Auto-generate Payload collections from Better Auth schema
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
type BetterAuthCollectionsOptions = {
|
|
13
|
+
/**
|
|
14
|
+
* Better Auth options. Pass the same options you use for betterAuth().
|
|
15
|
+
* The plugin reads the schema to generate collections.
|
|
16
|
+
*/
|
|
17
|
+
betterAuthOptions?: BetterAuthOptions;
|
|
18
|
+
/**
|
|
19
|
+
* Override collection slugs (e.g., { user: 'users', session: 'sessions' })
|
|
20
|
+
*/
|
|
21
|
+
slugOverrides?: Record<string, string>;
|
|
22
|
+
/**
|
|
23
|
+
* Collections to skip (they already exist in your config)
|
|
24
|
+
* Default: ['user'] - assumes you have a Users collection
|
|
25
|
+
*/
|
|
26
|
+
skipCollections?: string[];
|
|
27
|
+
/**
|
|
28
|
+
* Admin group name for generated collections
|
|
29
|
+
* Default: 'Auth'
|
|
30
|
+
*/
|
|
31
|
+
adminGroup?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Custom access control for generated collections.
|
|
34
|
+
* By default, only admins can read/delete, and create/update are disabled.
|
|
35
|
+
*/
|
|
36
|
+
access?: CollectionConfig['access'];
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Payload plugin that auto-generates collections from Better Auth schema.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* import { betterAuthCollections } from '@delmare/payload-better-auth'
|
|
44
|
+
*
|
|
45
|
+
* export default buildConfig({
|
|
46
|
+
* plugins: [
|
|
47
|
+
* betterAuthCollections({
|
|
48
|
+
* betterAuthOptions: { ... },
|
|
49
|
+
* skipCollections: ['user'], // Define Users yourself
|
|
50
|
+
* }),
|
|
51
|
+
* ],
|
|
52
|
+
* })
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
declare function betterAuthCollections(options?: BetterAuthCollectionsOptions): Plugin;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Server-side session utilities
|
|
59
|
+
*
|
|
60
|
+
* @packageDocumentation
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
type Session = {
|
|
64
|
+
user: {
|
|
65
|
+
id: string;
|
|
66
|
+
email: string;
|
|
67
|
+
name?: string;
|
|
68
|
+
image?: string;
|
|
69
|
+
[key: string]: unknown;
|
|
70
|
+
};
|
|
71
|
+
session: {
|
|
72
|
+
id: string;
|
|
73
|
+
expiresAt: Date;
|
|
74
|
+
[key: string]: unknown;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Get the current session from headers.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* import { headers } from 'next/headers'
|
|
83
|
+
* import { getServerSession } from '@delmare/payload-better-auth'
|
|
84
|
+
*
|
|
85
|
+
* export default async function Page() {
|
|
86
|
+
* const headersList = await headers()
|
|
87
|
+
* const session = await getServerSession(payload, headersList)
|
|
88
|
+
*
|
|
89
|
+
* if (!session) {
|
|
90
|
+
* redirect('/login')
|
|
91
|
+
* }
|
|
92
|
+
*
|
|
93
|
+
* return <div>Hello {session.user.name}</div>
|
|
94
|
+
* }
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
declare function getServerSession(payload: BasePayload, headers: Headers): Promise<Session | null>;
|
|
98
|
+
/**
|
|
99
|
+
* Get the current user from the session.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* import { headers } from 'next/headers'
|
|
104
|
+
* import { getServerUser } from '@delmare/payload-better-auth'
|
|
105
|
+
*
|
|
106
|
+
* export default async function Page() {
|
|
107
|
+
* const headersList = await headers()
|
|
108
|
+
* const user = await getServerUser(payload, headersList)
|
|
109
|
+
*
|
|
110
|
+
* if (!user) {
|
|
111
|
+
* redirect('/login')
|
|
112
|
+
* }
|
|
113
|
+
*
|
|
114
|
+
* return <div>Hello {user.name}</div>
|
|
115
|
+
* }
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
declare function getServerUser(payload: BasePayload, headers: Headers): Promise<Session['user'] | null>;
|
|
119
|
+
|
|
120
|
+
export { type BetterAuthCollectionsOptions, type Session, betterAuthCollections, getServerSession, getServerUser };
|