@playcademy/better-auth 0.0.1-alpha.1 → 0.0.1
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/dist/client.d.ts +88 -14
- package/dist/server.d.ts +111 -6
- package/package.json +2 -2
package/dist/client.d.ts
CHANGED
|
@@ -19,48 +19,122 @@
|
|
|
19
19
|
* ```
|
|
20
20
|
*/
|
|
21
21
|
import { playcademy as playcademyServerPlugin } from './server';
|
|
22
|
+
/**
|
|
23
|
+
* Configuration options for the Playcademy Better Auth client plugin
|
|
24
|
+
*
|
|
25
|
+
* Configures how the client handles platform authentication and Safari
|
|
26
|
+
* Storage Access API integration.
|
|
27
|
+
*/
|
|
22
28
|
export interface PlaycademyClientOptions {
|
|
23
29
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
* When true (default), Safari users in iframes will see an automatic
|
|
27
|
-
* prompt to grant storage access (required for cookies in Safari).
|
|
28
|
-
*
|
|
29
|
-
* Set to false if you want to handle Safari storage access yourself.
|
|
30
|
+
* Safari browser configuration.
|
|
30
31
|
*
|
|
31
|
-
*
|
|
32
|
+
* Controls how the plugin handles Safari's Storage Access API requirements
|
|
33
|
+
* for cross-origin cookies in iframes.
|
|
32
34
|
*/
|
|
33
35
|
safari?: {
|
|
36
|
+
/**
|
|
37
|
+
* Automatically show storage access prompt for Safari users.
|
|
38
|
+
*
|
|
39
|
+
* When `true` (default), Safari users running the game in an iframe
|
|
40
|
+
* (platform mode) will automatically see a prompt to grant cookie
|
|
41
|
+
* access. This is required for authentication to work in Safari iframes.
|
|
42
|
+
*
|
|
43
|
+
* Set to `false` if you want to handle Safari storage access manually
|
|
44
|
+
* or have a custom flow.
|
|
45
|
+
*
|
|
46
|
+
* **Why this is needed**: Safari blocks third-party cookies in iframes
|
|
47
|
+
* by default. The Storage Access API allows users to explicitly grant
|
|
48
|
+
* cookie access after a user interaction.
|
|
49
|
+
*
|
|
50
|
+
* @default true
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* {
|
|
54
|
+
* safari: {
|
|
55
|
+
* autoPrompt: true // Show automatic prompt (recommended)
|
|
56
|
+
* }
|
|
57
|
+
* }
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* {
|
|
63
|
+
* safari: {
|
|
64
|
+
* autoPrompt: false // Handle Safari auth manually
|
|
65
|
+
* }
|
|
66
|
+
* }
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
34
69
|
autoPrompt?: boolean;
|
|
35
70
|
};
|
|
36
71
|
}
|
|
37
72
|
/**
|
|
38
73
|
* Playcademy client plugin for Better Auth
|
|
39
74
|
*
|
|
40
|
-
*
|
|
41
|
-
* -
|
|
42
|
-
* -
|
|
43
|
-
*
|
|
75
|
+
* Enables seamless authentication for Playcademy games that run both:
|
|
76
|
+
* - In the Playcademy platform (iframe with JWT token exchange)
|
|
77
|
+
* - As standalone games (standard Better Auth with cookies)
|
|
78
|
+
*
|
|
79
|
+
* **Key Features**:
|
|
80
|
+
* - Automatic platform vs standalone mode detection
|
|
81
|
+
* - JWT token exchange for platform authentication
|
|
82
|
+
* - Safari Storage Access API handling (automatic prompt)
|
|
83
|
+
* - Cookie-based auth with CHIPS support for Chrome/Edge
|
|
84
|
+
* - Zero configuration required
|
|
85
|
+
*
|
|
86
|
+
* **How it works**:
|
|
87
|
+
* 1. Platform mode: Exchanges platform JWT for Better Auth session
|
|
88
|
+
* 2. Standalone mode: Uses standard Better Auth providers (email/OAuth)
|
|
89
|
+
* 3. Safari: Automatically requests storage access for iframe cookies
|
|
90
|
+
*
|
|
91
|
+
* @param options - Configuration options (optional)
|
|
92
|
+
* @returns Better Auth client plugin
|
|
44
93
|
*
|
|
45
94
|
* @example
|
|
46
95
|
* ```typescript
|
|
47
|
-
* //
|
|
96
|
+
* // Recommended: Use defaults (handles everything automatically)
|
|
97
|
+
* import { createAuthClient } from 'better-auth/react'
|
|
98
|
+
* import { playcademy } from '@playcademy/better-auth/client'
|
|
99
|
+
*
|
|
48
100
|
* const auth = createAuthClient({
|
|
101
|
+
* baseURL: 'http://localhost:8788',
|
|
49
102
|
* plugins: [playcademy()]
|
|
50
103
|
* })
|
|
104
|
+
*
|
|
105
|
+
* // Access auth in your components
|
|
106
|
+
* export const { useSession } = auth
|
|
51
107
|
* ```
|
|
52
108
|
*
|
|
53
109
|
* @example
|
|
54
110
|
* ```typescript
|
|
55
|
-
* // Custom: Disable
|
|
111
|
+
* // Custom: Disable Safari auto-prompt
|
|
56
112
|
* const auth = createAuthClient({
|
|
113
|
+
* baseURL: 'http://localhost:8788',
|
|
57
114
|
* plugins: [
|
|
58
115
|
* playcademy({
|
|
59
|
-
* safari: {
|
|
116
|
+
* safari: {
|
|
117
|
+
* autoPrompt: false // Handle Safari manually
|
|
118
|
+
* }
|
|
60
119
|
* })
|
|
61
120
|
* ]
|
|
62
121
|
* })
|
|
63
122
|
* ```
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```typescript
|
|
126
|
+
* // Use session in React component
|
|
127
|
+
* import { useSession } from './lib/auth'
|
|
128
|
+
*
|
|
129
|
+
* function App() {
|
|
130
|
+
* const { data: session, isPending } = useSession()
|
|
131
|
+
*
|
|
132
|
+
* if (isPending) return <div>Loading...</div>
|
|
133
|
+
* if (!session) return <div>Not logged in</div>
|
|
134
|
+
*
|
|
135
|
+
* return <div>Welcome, {session.user.name}!</div>
|
|
136
|
+
* }
|
|
137
|
+
* ```
|
|
64
138
|
*/
|
|
65
139
|
export declare function playcademy(options?: PlaycademyClientOptions): {
|
|
66
140
|
id: "playcademy-client";
|
package/dist/server.d.ts
CHANGED
|
@@ -1,30 +1,135 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Playcademy
|
|
2
|
+
* Playcademy Platform Authentication Plugin (Server)
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* -
|
|
6
|
-
* -
|
|
4
|
+
* Enables seamless authentication for Playcademy games that run both:
|
|
5
|
+
* - In the Playcademy platform (iframe with JWT token exchange)
|
|
6
|
+
* - As standalone games (standard Better Auth with cookies)
|
|
7
|
+
*
|
|
8
|
+
* **Key Features**:
|
|
9
|
+
* - Platform JWT token exchange endpoint (`POST /api/auth/playcademy`)
|
|
7
10
|
* - Automatic account linking between platform and standalone modes
|
|
8
|
-
* - Cross-site cookie support with CHIPS
|
|
11
|
+
* - Cross-site cookie support with CHIPS (Partitioned cookies)
|
|
12
|
+
* - Schema extension: adds `playcademyUserId` to user model
|
|
13
|
+
* - Safari Storage Access API compatibility
|
|
14
|
+
*
|
|
15
|
+
* **How it works**:
|
|
16
|
+
*
|
|
17
|
+
* 1. **Platform Mode (iframe)**:
|
|
18
|
+
* - Game receives JWT token from Playcademy platform
|
|
19
|
+
* - Client exchanges token via `/api/auth/playcademy` endpoint
|
|
20
|
+
* - Server verifies token with platform API
|
|
21
|
+
* - Creates or links Better Auth user by `playcademyUserId`
|
|
22
|
+
* - Returns session cookie with CHIPS support
|
|
23
|
+
*
|
|
24
|
+
* 2. **Standalone Mode**:
|
|
25
|
+
* - Users authenticate via Better Auth providers (email, OAuth, etc.)
|
|
26
|
+
* - If they later access via platform, accounts are linked by `playcademyUserId`
|
|
27
|
+
*
|
|
28
|
+
* 3. **Account Linking**:
|
|
29
|
+
* - Platform users get `playcademyUserId` set automatically
|
|
30
|
+
* - If a user exists with that `playcademyUserId`, sessions merge
|
|
31
|
+
* - Enables seamless switching between platform and standalone
|
|
32
|
+
*
|
|
33
|
+
* **Cookie Configuration**:
|
|
34
|
+
*
|
|
35
|
+
* For cross-origin iframe authentication to work, you MUST configure cookies:
|
|
36
|
+
*
|
|
37
|
+
* ```typescript
|
|
38
|
+
* advanced: {
|
|
39
|
+
* defaultCookieAttributes: {
|
|
40
|
+
* sameSite: 'none', // Allow cross-site cookies
|
|
41
|
+
* secure: true, // HTTPS only (required for sameSite: none)
|
|
42
|
+
* path: '/', // Available across entire site
|
|
43
|
+
* partitioned: true, // CHIPS for Chrome/Edge
|
|
44
|
+
* }
|
|
45
|
+
* }
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* **Safari Compatibility**:
|
|
49
|
+
*
|
|
50
|
+
* Safari doesn't support CHIPS. The client plugin automatically handles
|
|
51
|
+
* Safari Storage Access API to request cookie permission from users.
|
|
52
|
+
*
|
|
53
|
+
* @returns Better Auth server plugin
|
|
9
54
|
*
|
|
10
55
|
* @example
|
|
11
56
|
* ```typescript
|
|
57
|
+
* // Basic setup
|
|
12
58
|
* import { betterAuth } from 'better-auth'
|
|
59
|
+
* import { drizzleAdapter } from 'better-auth/adapters/drizzle'
|
|
13
60
|
* import { playcademy } from '@playcademy/better-auth/server'
|
|
61
|
+
* import { db } from './db'
|
|
14
62
|
*
|
|
15
63
|
* export const auth = betterAuth({
|
|
16
64
|
* database: drizzleAdapter(db, { provider: 'sqlite' }),
|
|
65
|
+
*
|
|
66
|
+
* // Required: Platform integration
|
|
17
67
|
* plugins: [playcademy()],
|
|
68
|
+
*
|
|
69
|
+
* // Required: Cross-site cookie support
|
|
18
70
|
* advanced: {
|
|
19
71
|
* defaultCookieAttributes: {
|
|
20
72
|
* sameSite: 'none',
|
|
21
73
|
* secure: true,
|
|
22
74
|
* path: '/',
|
|
23
75
|
* partitioned: true, // CHIPS for Chrome/Edge
|
|
24
|
-
* }
|
|
76
|
+
* }
|
|
77
|
+
* }
|
|
78
|
+
* })
|
|
79
|
+
* ```
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* // With email/password and OAuth
|
|
84
|
+
* export const auth = betterAuth({
|
|
85
|
+
* database: drizzleAdapter(db, { provider: 'sqlite' }),
|
|
86
|
+
*
|
|
87
|
+
* // Platform auth (always included)
|
|
88
|
+
* plugins: [playcademy()],
|
|
89
|
+
*
|
|
90
|
+
* // Optional: Email/password for standalone
|
|
91
|
+
* emailAndPassword: {
|
|
92
|
+
* enabled: true
|
|
25
93
|
* },
|
|
94
|
+
*
|
|
95
|
+
* // Optional: OAuth for standalone
|
|
96
|
+
* socialProviders: {
|
|
97
|
+
* github: {
|
|
98
|
+
* clientId: process.env.GITHUB_CLIENT_ID!,
|
|
99
|
+
* clientSecret: process.env.GITHUB_CLIENT_SECRET!,
|
|
100
|
+
* }
|
|
101
|
+
* },
|
|
102
|
+
*
|
|
103
|
+
* advanced: {
|
|
104
|
+
* defaultCookieAttributes: {
|
|
105
|
+
* sameSite: 'none',
|
|
106
|
+
* secure: true,
|
|
107
|
+
* path: '/',
|
|
108
|
+
* partitioned: true,
|
|
109
|
+
* }
|
|
110
|
+
* }
|
|
26
111
|
* })
|
|
27
112
|
* ```
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* // Use in API route handler
|
|
117
|
+
* import { Context } from 'hono'
|
|
118
|
+
* import { auth } from './lib/auth'
|
|
119
|
+
*
|
|
120
|
+
* export async function GET(c: Context) {
|
|
121
|
+
* const session = await auth.api.getSession({
|
|
122
|
+
* headers: c.req.raw.headers
|
|
123
|
+
* })
|
|
124
|
+
*
|
|
125
|
+
* if (!session) {
|
|
126
|
+
* return c.json({ error: 'Unauthorized' }, 401)
|
|
127
|
+
* }
|
|
128
|
+
*
|
|
129
|
+
* // session.user.playcademyUserId available if from platform
|
|
130
|
+
* return c.json({ user: session.user })
|
|
131
|
+
* }
|
|
132
|
+
* ```
|
|
28
133
|
*/
|
|
29
134
|
export declare const playcademy: () => {
|
|
30
135
|
id: "playcademy";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@playcademy/better-auth",
|
|
3
|
-
"version": "0.0.1
|
|
3
|
+
"version": "0.0.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./server": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@inquirer/prompts": "^7.9.0",
|
|
31
|
-
"@playcademy/sdk": "0.1.
|
|
31
|
+
"@playcademy/sdk": "0.1.14",
|
|
32
32
|
"@playcademy/utils": "0.0.1",
|
|
33
33
|
"@types/bun": "latest",
|
|
34
34
|
"typescript": "^5.7.2"
|