@githat/nextjs 0.2.0 → 0.2.2
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/README.md +584 -48
- package/dist/githat.css +41 -0
- package/dist/index.d.mts +213 -2
- package/dist/index.d.ts +213 -2
- package/dist/index.js +792 -96
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +786 -95
- package/dist/index.mjs.map +1 -1
- package/dist/middleware.d.mts +73 -4
- package/dist/middleware.d.ts +73 -4
- package/dist/middleware.js +96 -12
- package/dist/middleware.js.map +1 -1
- package/dist/middleware.mjs +85 -13
- package/dist/middleware.mjs.map +1 -1
- package/dist/proxy.d.mts +78 -0
- package/dist/proxy.d.ts +78 -0
- package/dist/proxy.js +138 -0
- package/dist/proxy.js.map +1 -0
- package/dist/proxy.mjs +101 -0
- package/dist/proxy.mjs.map +1 -0
- package/dist/server.d.mts +164 -0
- package/dist/server.d.ts +164 -0
- package/dist/server.js +203 -0
- package/dist/server.js.map +1 -0
- package/dist/server.mjs +163 -0
- package/dist/server.mjs.map +1 -0
- package/package.json +23 -3
package/dist/githat.css
CHANGED
|
@@ -332,3 +332,44 @@
|
|
|
332
332
|
color: #a1a1aa;
|
|
333
333
|
font-size: 0.875rem;
|
|
334
334
|
}
|
|
335
|
+
|
|
336
|
+
/* Dev Mode Banner */
|
|
337
|
+
.githat-dev-banner {
|
|
338
|
+
position: fixed;
|
|
339
|
+
top: 0;
|
|
340
|
+
left: 0;
|
|
341
|
+
right: 0;
|
|
342
|
+
z-index: 99999;
|
|
343
|
+
display: flex;
|
|
344
|
+
align-items: center;
|
|
345
|
+
justify-content: space-between;
|
|
346
|
+
padding: 0.5rem 1rem;
|
|
347
|
+
background: #fef3c7;
|
|
348
|
+
border-bottom: 1px solid #f59e0b;
|
|
349
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
350
|
+
font-size: 0.8125rem;
|
|
351
|
+
color: #92400e;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
.githat-dev-banner a {
|
|
355
|
+
color: #d97706;
|
|
356
|
+
font-weight: 600;
|
|
357
|
+
text-decoration: underline;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
.githat-dev-banner button {
|
|
361
|
+
background: none;
|
|
362
|
+
border: none;
|
|
363
|
+
color: #92400e;
|
|
364
|
+
font-size: 1.25rem;
|
|
365
|
+
cursor: pointer;
|
|
366
|
+
padding: 0 0.25rem;
|
|
367
|
+
line-height: 1;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/* Success Alert */
|
|
371
|
+
.githat-alert-success {
|
|
372
|
+
background: rgba(16, 185, 129, 0.1);
|
|
373
|
+
border: 1px solid rgba(16, 185, 129, 0.3);
|
|
374
|
+
color: #6ee7b7;
|
|
375
|
+
}
|
package/dist/index.d.mts
CHANGED
|
@@ -22,6 +22,17 @@ interface GitHatConfig {
|
|
|
22
22
|
signUpUrl?: string;
|
|
23
23
|
afterSignInUrl?: string;
|
|
24
24
|
afterSignOutUrl?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Token storage mode:
|
|
27
|
+
* - 'localStorage' (default): Tokens stored in browser localStorage
|
|
28
|
+
* - 'cookie': Tokens stored in httpOnly cookies (more secure, XSS-resistant)
|
|
29
|
+
*
|
|
30
|
+
* When using 'cookie' mode:
|
|
31
|
+
* - Login/refresh automatically set httpOnly cookies
|
|
32
|
+
* - SDK reads auth state from cookies (server-side)
|
|
33
|
+
* - Better for apps with server-side rendering
|
|
34
|
+
*/
|
|
35
|
+
tokenStorage?: 'localStorage' | 'cookie';
|
|
25
36
|
}
|
|
26
37
|
interface AuthState {
|
|
27
38
|
user: GitHatUser | null;
|
|
@@ -49,6 +60,12 @@ interface SignUpResult {
|
|
|
49
60
|
interface GitHatContextValue extends AuthState, AuthActions {
|
|
50
61
|
config: GitHatConfig;
|
|
51
62
|
}
|
|
63
|
+
interface PasswordResetResult {
|
|
64
|
+
success: boolean;
|
|
65
|
+
}
|
|
66
|
+
interface EmailVerificationResult {
|
|
67
|
+
success: boolean;
|
|
68
|
+
}
|
|
52
69
|
|
|
53
70
|
interface GitHatProviderProps {
|
|
54
71
|
config: GitHatConfig;
|
|
@@ -56,9 +73,12 @@ interface GitHatProviderProps {
|
|
|
56
73
|
}
|
|
57
74
|
declare function GitHatProvider({ config: rawConfig, children }: GitHatProviderProps): react_jsx_runtime.JSX.Element;
|
|
58
75
|
|
|
76
|
+
interface OrgMetadata$1 {
|
|
77
|
+
[key: string]: unknown;
|
|
78
|
+
}
|
|
59
79
|
declare function useAuth(): GitHatContextValue;
|
|
60
80
|
declare function useGitHat(): {
|
|
61
|
-
fetch: <T =
|
|
81
|
+
fetch: <T = unknown>(endpoint: string, fetchOptions?: RequestInit) => Promise<T>;
|
|
62
82
|
getUserOrgs: () => Promise<{
|
|
63
83
|
orgs: GitHatOrg[];
|
|
64
84
|
}>;
|
|
@@ -68,6 +88,116 @@ declare function useGitHat(): {
|
|
|
68
88
|
verifyAgent: (wallet: string) => Promise<{
|
|
69
89
|
verified: boolean;
|
|
70
90
|
}>;
|
|
91
|
+
getOrgMetadata: () => Promise<OrgMetadata$1>;
|
|
92
|
+
updateOrgMetadata: (updates: OrgMetadata$1) => Promise<OrgMetadata$1>;
|
|
93
|
+
forgotPassword: (email: string) => Promise<{
|
|
94
|
+
success: boolean;
|
|
95
|
+
}>;
|
|
96
|
+
resetPassword: (token: string, newPassword: string) => Promise<{
|
|
97
|
+
success: boolean;
|
|
98
|
+
}>;
|
|
99
|
+
changePassword: (currentPassword: string, newPassword: string) => Promise<{
|
|
100
|
+
success: boolean;
|
|
101
|
+
}>;
|
|
102
|
+
verifyEmail: (token: string) => Promise<{
|
|
103
|
+
success: boolean;
|
|
104
|
+
}>;
|
|
105
|
+
resendVerificationEmail: (email: string) => Promise<{
|
|
106
|
+
success: boolean;
|
|
107
|
+
}>;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
interface DataItem {
|
|
111
|
+
id: string;
|
|
112
|
+
[key: string]: unknown;
|
|
113
|
+
_createdAt?: string;
|
|
114
|
+
_updatedAt?: string;
|
|
115
|
+
}
|
|
116
|
+
interface QueryOptions {
|
|
117
|
+
limit?: number;
|
|
118
|
+
cursor?: string;
|
|
119
|
+
filter?: Record<string, unknown>;
|
|
120
|
+
}
|
|
121
|
+
interface QueryResult<T = DataItem> {
|
|
122
|
+
items: T[];
|
|
123
|
+
collection: string;
|
|
124
|
+
nextCursor: string | null;
|
|
125
|
+
count: number;
|
|
126
|
+
}
|
|
127
|
+
interface PutResult<T = DataItem> {
|
|
128
|
+
item: T;
|
|
129
|
+
collection: string;
|
|
130
|
+
created: boolean;
|
|
131
|
+
}
|
|
132
|
+
interface DeleteResult {
|
|
133
|
+
deleted: boolean;
|
|
134
|
+
id: string;
|
|
135
|
+
collection: string;
|
|
136
|
+
}
|
|
137
|
+
interface BatchOperation {
|
|
138
|
+
type: 'put' | 'delete';
|
|
139
|
+
id: string;
|
|
140
|
+
data?: Record<string, unknown>;
|
|
141
|
+
}
|
|
142
|
+
interface BatchResult {
|
|
143
|
+
processed: number;
|
|
144
|
+
put: number;
|
|
145
|
+
deleted: number;
|
|
146
|
+
collection: string;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Hook for interacting with GitHat's Customer Data API.
|
|
150
|
+
* Provides CRUD operations for storing app data in GitHat's managed DynamoDB.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```tsx
|
|
154
|
+
* const { put, get, query, remove, batch } = useData();
|
|
155
|
+
*
|
|
156
|
+
* // Store data
|
|
157
|
+
* await put('orders', { id: 'order_123', amount: 99.99, status: 'pending' });
|
|
158
|
+
*
|
|
159
|
+
* // Get single item
|
|
160
|
+
* const order = await get('orders', 'order_123');
|
|
161
|
+
*
|
|
162
|
+
* // Query collection
|
|
163
|
+
* const { items } = await query('orders', { filter: { status: 'pending' } });
|
|
164
|
+
*
|
|
165
|
+
* // Delete item
|
|
166
|
+
* await remove('orders', 'order_123');
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
declare function useData(): {
|
|
170
|
+
/**
|
|
171
|
+
* Store an item in a collection. If the item exists, it will be updated.
|
|
172
|
+
* @param collection - Collection name (e.g., 'orders', 'users')
|
|
173
|
+
* @param data - Data object with required `id` field
|
|
174
|
+
*/
|
|
175
|
+
put: <T extends DataItem>(collection: string, data: T) => Promise<PutResult<T>>;
|
|
176
|
+
/**
|
|
177
|
+
* Get a single item from a collection.
|
|
178
|
+
* @param collection - Collection name
|
|
179
|
+
* @param id - Item ID
|
|
180
|
+
*/
|
|
181
|
+
get: <T extends DataItem>(collection: string, id: string) => Promise<T | null>;
|
|
182
|
+
/**
|
|
183
|
+
* Query items from a collection with optional filters and pagination.
|
|
184
|
+
* @param collection - Collection name
|
|
185
|
+
* @param options - Query options (limit, cursor, filter)
|
|
186
|
+
*/
|
|
187
|
+
query: <T extends DataItem>(collection: string, options?: QueryOptions) => Promise<QueryResult<T>>;
|
|
188
|
+
/**
|
|
189
|
+
* Delete an item from a collection.
|
|
190
|
+
* @param collection - Collection name
|
|
191
|
+
* @param id - Item ID
|
|
192
|
+
*/
|
|
193
|
+
remove: (collection: string, id: string) => Promise<DeleteResult>;
|
|
194
|
+
/**
|
|
195
|
+
* Batch operations (put/delete) on a collection.
|
|
196
|
+
* Maximum 100 operations per request.
|
|
197
|
+
* @param collection - Collection name
|
|
198
|
+
* @param operations - Array of operations
|
|
199
|
+
*/
|
|
200
|
+
batch: (collection: string, operations: BatchOperation[]) => Promise<BatchResult>;
|
|
71
201
|
};
|
|
72
202
|
|
|
73
203
|
interface SignInFormProps {
|
|
@@ -117,4 +247,85 @@ interface ProtectedRouteProps {
|
|
|
117
247
|
}
|
|
118
248
|
declare function ProtectedRoute({ children, fallback }: ProtectedRouteProps): react_jsx_runtime.JSX.Element | null;
|
|
119
249
|
|
|
120
|
-
|
|
250
|
+
interface ForgotPasswordFormProps {
|
|
251
|
+
onSuccess?: (email: string) => void;
|
|
252
|
+
onError?: (error: Error) => void;
|
|
253
|
+
signInUrl?: string;
|
|
254
|
+
}
|
|
255
|
+
declare function ForgotPasswordForm({ onSuccess, onError, signInUrl, }: ForgotPasswordFormProps): react_jsx_runtime.JSX.Element;
|
|
256
|
+
|
|
257
|
+
interface ResetPasswordFormProps {
|
|
258
|
+
token: string;
|
|
259
|
+
onSuccess?: () => void;
|
|
260
|
+
onError?: (error: Error) => void;
|
|
261
|
+
signInUrl?: string;
|
|
262
|
+
minPasswordLength?: number;
|
|
263
|
+
}
|
|
264
|
+
declare function ResetPasswordForm({ token, onSuccess, onError, signInUrl, minPasswordLength, }: ResetPasswordFormProps): react_jsx_runtime.JSX.Element;
|
|
265
|
+
|
|
266
|
+
interface VerifyEmailStatusProps {
|
|
267
|
+
token: string;
|
|
268
|
+
onSuccess?: () => void;
|
|
269
|
+
onError?: (error: Error) => void;
|
|
270
|
+
signInUrl?: string;
|
|
271
|
+
redirectDelay?: number;
|
|
272
|
+
}
|
|
273
|
+
declare function VerifyEmailStatus({ token, onSuccess, onError, signInUrl, redirectDelay, }: VerifyEmailStatusProps): react_jsx_runtime.JSX.Element;
|
|
274
|
+
|
|
275
|
+
interface ChangePasswordFormProps {
|
|
276
|
+
onSuccess?: () => void;
|
|
277
|
+
onError?: (error: Error) => void;
|
|
278
|
+
minPasswordLength?: number;
|
|
279
|
+
}
|
|
280
|
+
declare function ChangePasswordForm({ onSuccess, onError, minPasswordLength, }: ChangePasswordFormProps): react_jsx_runtime.JSX.Element;
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* @githat/nextjs/server
|
|
284
|
+
*
|
|
285
|
+
* Server-side utilities for token verification in Next.js API routes and middleware.
|
|
286
|
+
* This module runs on the server only — do not import in client components.
|
|
287
|
+
*/
|
|
288
|
+
interface AuthPayload {
|
|
289
|
+
userId: string;
|
|
290
|
+
email: string;
|
|
291
|
+
orgId: string | null;
|
|
292
|
+
orgSlug: string | null;
|
|
293
|
+
role: 'owner' | 'admin' | 'member' | null;
|
|
294
|
+
tier: 'free' | 'basic' | 'pro' | 'enterprise' | null;
|
|
295
|
+
}
|
|
296
|
+
interface VerifyOptions {
|
|
297
|
+
/**
|
|
298
|
+
* Secret key for local JWT verification. If provided, tokens are verified
|
|
299
|
+
* locally without making an API call (~1ms vs ~50-100ms).
|
|
300
|
+
* Must match the JWT_SECRET used by the GitHat backend.
|
|
301
|
+
*/
|
|
302
|
+
secretKey?: string;
|
|
303
|
+
/**
|
|
304
|
+
* API URL for remote token verification. Defaults to https://api.githat.io
|
|
305
|
+
*/
|
|
306
|
+
apiUrl?: string;
|
|
307
|
+
}
|
|
308
|
+
interface OrgMetadata {
|
|
309
|
+
[key: string]: unknown;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Handler function that receives the request and verified auth payload.
|
|
313
|
+
*/
|
|
314
|
+
type AuthenticatedHandler = (request: Request, auth: AuthPayload) => Promise<Response> | Response;
|
|
315
|
+
/**
|
|
316
|
+
* Options for the withAuth wrapper.
|
|
317
|
+
*/
|
|
318
|
+
interface WithAuthOptions {
|
|
319
|
+
/**
|
|
320
|
+
* Secret key for local JWT verification.
|
|
321
|
+
* Defaults to process.env.GITHAT_SECRET_KEY if not provided.
|
|
322
|
+
*/
|
|
323
|
+
secretKey?: string;
|
|
324
|
+
/**
|
|
325
|
+
* Custom response to return when authentication fails.
|
|
326
|
+
* Defaults to JSON { error: 'Unauthorized' } with status 401.
|
|
327
|
+
*/
|
|
328
|
+
onUnauthorized?: () => Response;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
export { type AuthActions, type AuthPayload, type AuthState, type AuthenticatedHandler, type BatchOperation, type BatchResult, ChangePasswordForm, type DataItem, type DeleteResult, type EmailVerificationResult, ForgotPasswordForm, type GitHatConfig, type GitHatContextValue, type GitHatOrg, GitHatProvider, type GitHatUser, type OrgMetadata, OrgSwitcher, type PasswordResetResult, ProtectedRoute, type PutResult, type QueryOptions, type QueryResult, ResetPasswordForm, SignInButton, SignInForm, SignUpButton, type SignUpData, SignUpForm, type SignUpResult, UserButton, VerifiedBadge, VerifyEmailStatus, type VerifyOptions, type WithAuthOptions, useAuth, useData, useGitHat };
|
package/dist/index.d.ts
CHANGED
|
@@ -22,6 +22,17 @@ interface GitHatConfig {
|
|
|
22
22
|
signUpUrl?: string;
|
|
23
23
|
afterSignInUrl?: string;
|
|
24
24
|
afterSignOutUrl?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Token storage mode:
|
|
27
|
+
* - 'localStorage' (default): Tokens stored in browser localStorage
|
|
28
|
+
* - 'cookie': Tokens stored in httpOnly cookies (more secure, XSS-resistant)
|
|
29
|
+
*
|
|
30
|
+
* When using 'cookie' mode:
|
|
31
|
+
* - Login/refresh automatically set httpOnly cookies
|
|
32
|
+
* - SDK reads auth state from cookies (server-side)
|
|
33
|
+
* - Better for apps with server-side rendering
|
|
34
|
+
*/
|
|
35
|
+
tokenStorage?: 'localStorage' | 'cookie';
|
|
25
36
|
}
|
|
26
37
|
interface AuthState {
|
|
27
38
|
user: GitHatUser | null;
|
|
@@ -49,6 +60,12 @@ interface SignUpResult {
|
|
|
49
60
|
interface GitHatContextValue extends AuthState, AuthActions {
|
|
50
61
|
config: GitHatConfig;
|
|
51
62
|
}
|
|
63
|
+
interface PasswordResetResult {
|
|
64
|
+
success: boolean;
|
|
65
|
+
}
|
|
66
|
+
interface EmailVerificationResult {
|
|
67
|
+
success: boolean;
|
|
68
|
+
}
|
|
52
69
|
|
|
53
70
|
interface GitHatProviderProps {
|
|
54
71
|
config: GitHatConfig;
|
|
@@ -56,9 +73,12 @@ interface GitHatProviderProps {
|
|
|
56
73
|
}
|
|
57
74
|
declare function GitHatProvider({ config: rawConfig, children }: GitHatProviderProps): react_jsx_runtime.JSX.Element;
|
|
58
75
|
|
|
76
|
+
interface OrgMetadata$1 {
|
|
77
|
+
[key: string]: unknown;
|
|
78
|
+
}
|
|
59
79
|
declare function useAuth(): GitHatContextValue;
|
|
60
80
|
declare function useGitHat(): {
|
|
61
|
-
fetch: <T =
|
|
81
|
+
fetch: <T = unknown>(endpoint: string, fetchOptions?: RequestInit) => Promise<T>;
|
|
62
82
|
getUserOrgs: () => Promise<{
|
|
63
83
|
orgs: GitHatOrg[];
|
|
64
84
|
}>;
|
|
@@ -68,6 +88,116 @@ declare function useGitHat(): {
|
|
|
68
88
|
verifyAgent: (wallet: string) => Promise<{
|
|
69
89
|
verified: boolean;
|
|
70
90
|
}>;
|
|
91
|
+
getOrgMetadata: () => Promise<OrgMetadata$1>;
|
|
92
|
+
updateOrgMetadata: (updates: OrgMetadata$1) => Promise<OrgMetadata$1>;
|
|
93
|
+
forgotPassword: (email: string) => Promise<{
|
|
94
|
+
success: boolean;
|
|
95
|
+
}>;
|
|
96
|
+
resetPassword: (token: string, newPassword: string) => Promise<{
|
|
97
|
+
success: boolean;
|
|
98
|
+
}>;
|
|
99
|
+
changePassword: (currentPassword: string, newPassword: string) => Promise<{
|
|
100
|
+
success: boolean;
|
|
101
|
+
}>;
|
|
102
|
+
verifyEmail: (token: string) => Promise<{
|
|
103
|
+
success: boolean;
|
|
104
|
+
}>;
|
|
105
|
+
resendVerificationEmail: (email: string) => Promise<{
|
|
106
|
+
success: boolean;
|
|
107
|
+
}>;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
interface DataItem {
|
|
111
|
+
id: string;
|
|
112
|
+
[key: string]: unknown;
|
|
113
|
+
_createdAt?: string;
|
|
114
|
+
_updatedAt?: string;
|
|
115
|
+
}
|
|
116
|
+
interface QueryOptions {
|
|
117
|
+
limit?: number;
|
|
118
|
+
cursor?: string;
|
|
119
|
+
filter?: Record<string, unknown>;
|
|
120
|
+
}
|
|
121
|
+
interface QueryResult<T = DataItem> {
|
|
122
|
+
items: T[];
|
|
123
|
+
collection: string;
|
|
124
|
+
nextCursor: string | null;
|
|
125
|
+
count: number;
|
|
126
|
+
}
|
|
127
|
+
interface PutResult<T = DataItem> {
|
|
128
|
+
item: T;
|
|
129
|
+
collection: string;
|
|
130
|
+
created: boolean;
|
|
131
|
+
}
|
|
132
|
+
interface DeleteResult {
|
|
133
|
+
deleted: boolean;
|
|
134
|
+
id: string;
|
|
135
|
+
collection: string;
|
|
136
|
+
}
|
|
137
|
+
interface BatchOperation {
|
|
138
|
+
type: 'put' | 'delete';
|
|
139
|
+
id: string;
|
|
140
|
+
data?: Record<string, unknown>;
|
|
141
|
+
}
|
|
142
|
+
interface BatchResult {
|
|
143
|
+
processed: number;
|
|
144
|
+
put: number;
|
|
145
|
+
deleted: number;
|
|
146
|
+
collection: string;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Hook for interacting with GitHat's Customer Data API.
|
|
150
|
+
* Provides CRUD operations for storing app data in GitHat's managed DynamoDB.
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```tsx
|
|
154
|
+
* const { put, get, query, remove, batch } = useData();
|
|
155
|
+
*
|
|
156
|
+
* // Store data
|
|
157
|
+
* await put('orders', { id: 'order_123', amount: 99.99, status: 'pending' });
|
|
158
|
+
*
|
|
159
|
+
* // Get single item
|
|
160
|
+
* const order = await get('orders', 'order_123');
|
|
161
|
+
*
|
|
162
|
+
* // Query collection
|
|
163
|
+
* const { items } = await query('orders', { filter: { status: 'pending' } });
|
|
164
|
+
*
|
|
165
|
+
* // Delete item
|
|
166
|
+
* await remove('orders', 'order_123');
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
declare function useData(): {
|
|
170
|
+
/**
|
|
171
|
+
* Store an item in a collection. If the item exists, it will be updated.
|
|
172
|
+
* @param collection - Collection name (e.g., 'orders', 'users')
|
|
173
|
+
* @param data - Data object with required `id` field
|
|
174
|
+
*/
|
|
175
|
+
put: <T extends DataItem>(collection: string, data: T) => Promise<PutResult<T>>;
|
|
176
|
+
/**
|
|
177
|
+
* Get a single item from a collection.
|
|
178
|
+
* @param collection - Collection name
|
|
179
|
+
* @param id - Item ID
|
|
180
|
+
*/
|
|
181
|
+
get: <T extends DataItem>(collection: string, id: string) => Promise<T | null>;
|
|
182
|
+
/**
|
|
183
|
+
* Query items from a collection with optional filters and pagination.
|
|
184
|
+
* @param collection - Collection name
|
|
185
|
+
* @param options - Query options (limit, cursor, filter)
|
|
186
|
+
*/
|
|
187
|
+
query: <T extends DataItem>(collection: string, options?: QueryOptions) => Promise<QueryResult<T>>;
|
|
188
|
+
/**
|
|
189
|
+
* Delete an item from a collection.
|
|
190
|
+
* @param collection - Collection name
|
|
191
|
+
* @param id - Item ID
|
|
192
|
+
*/
|
|
193
|
+
remove: (collection: string, id: string) => Promise<DeleteResult>;
|
|
194
|
+
/**
|
|
195
|
+
* Batch operations (put/delete) on a collection.
|
|
196
|
+
* Maximum 100 operations per request.
|
|
197
|
+
* @param collection - Collection name
|
|
198
|
+
* @param operations - Array of operations
|
|
199
|
+
*/
|
|
200
|
+
batch: (collection: string, operations: BatchOperation[]) => Promise<BatchResult>;
|
|
71
201
|
};
|
|
72
202
|
|
|
73
203
|
interface SignInFormProps {
|
|
@@ -117,4 +247,85 @@ interface ProtectedRouteProps {
|
|
|
117
247
|
}
|
|
118
248
|
declare function ProtectedRoute({ children, fallback }: ProtectedRouteProps): react_jsx_runtime.JSX.Element | null;
|
|
119
249
|
|
|
120
|
-
|
|
250
|
+
interface ForgotPasswordFormProps {
|
|
251
|
+
onSuccess?: (email: string) => void;
|
|
252
|
+
onError?: (error: Error) => void;
|
|
253
|
+
signInUrl?: string;
|
|
254
|
+
}
|
|
255
|
+
declare function ForgotPasswordForm({ onSuccess, onError, signInUrl, }: ForgotPasswordFormProps): react_jsx_runtime.JSX.Element;
|
|
256
|
+
|
|
257
|
+
interface ResetPasswordFormProps {
|
|
258
|
+
token: string;
|
|
259
|
+
onSuccess?: () => void;
|
|
260
|
+
onError?: (error: Error) => void;
|
|
261
|
+
signInUrl?: string;
|
|
262
|
+
minPasswordLength?: number;
|
|
263
|
+
}
|
|
264
|
+
declare function ResetPasswordForm({ token, onSuccess, onError, signInUrl, minPasswordLength, }: ResetPasswordFormProps): react_jsx_runtime.JSX.Element;
|
|
265
|
+
|
|
266
|
+
interface VerifyEmailStatusProps {
|
|
267
|
+
token: string;
|
|
268
|
+
onSuccess?: () => void;
|
|
269
|
+
onError?: (error: Error) => void;
|
|
270
|
+
signInUrl?: string;
|
|
271
|
+
redirectDelay?: number;
|
|
272
|
+
}
|
|
273
|
+
declare function VerifyEmailStatus({ token, onSuccess, onError, signInUrl, redirectDelay, }: VerifyEmailStatusProps): react_jsx_runtime.JSX.Element;
|
|
274
|
+
|
|
275
|
+
interface ChangePasswordFormProps {
|
|
276
|
+
onSuccess?: () => void;
|
|
277
|
+
onError?: (error: Error) => void;
|
|
278
|
+
minPasswordLength?: number;
|
|
279
|
+
}
|
|
280
|
+
declare function ChangePasswordForm({ onSuccess, onError, minPasswordLength, }: ChangePasswordFormProps): react_jsx_runtime.JSX.Element;
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* @githat/nextjs/server
|
|
284
|
+
*
|
|
285
|
+
* Server-side utilities for token verification in Next.js API routes and middleware.
|
|
286
|
+
* This module runs on the server only — do not import in client components.
|
|
287
|
+
*/
|
|
288
|
+
interface AuthPayload {
|
|
289
|
+
userId: string;
|
|
290
|
+
email: string;
|
|
291
|
+
orgId: string | null;
|
|
292
|
+
orgSlug: string | null;
|
|
293
|
+
role: 'owner' | 'admin' | 'member' | null;
|
|
294
|
+
tier: 'free' | 'basic' | 'pro' | 'enterprise' | null;
|
|
295
|
+
}
|
|
296
|
+
interface VerifyOptions {
|
|
297
|
+
/**
|
|
298
|
+
* Secret key for local JWT verification. If provided, tokens are verified
|
|
299
|
+
* locally without making an API call (~1ms vs ~50-100ms).
|
|
300
|
+
* Must match the JWT_SECRET used by the GitHat backend.
|
|
301
|
+
*/
|
|
302
|
+
secretKey?: string;
|
|
303
|
+
/**
|
|
304
|
+
* API URL for remote token verification. Defaults to https://api.githat.io
|
|
305
|
+
*/
|
|
306
|
+
apiUrl?: string;
|
|
307
|
+
}
|
|
308
|
+
interface OrgMetadata {
|
|
309
|
+
[key: string]: unknown;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Handler function that receives the request and verified auth payload.
|
|
313
|
+
*/
|
|
314
|
+
type AuthenticatedHandler = (request: Request, auth: AuthPayload) => Promise<Response> | Response;
|
|
315
|
+
/**
|
|
316
|
+
* Options for the withAuth wrapper.
|
|
317
|
+
*/
|
|
318
|
+
interface WithAuthOptions {
|
|
319
|
+
/**
|
|
320
|
+
* Secret key for local JWT verification.
|
|
321
|
+
* Defaults to process.env.GITHAT_SECRET_KEY if not provided.
|
|
322
|
+
*/
|
|
323
|
+
secretKey?: string;
|
|
324
|
+
/**
|
|
325
|
+
* Custom response to return when authentication fails.
|
|
326
|
+
* Defaults to JSON { error: 'Unauthorized' } with status 401.
|
|
327
|
+
*/
|
|
328
|
+
onUnauthorized?: () => Response;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
export { type AuthActions, type AuthPayload, type AuthState, type AuthenticatedHandler, type BatchOperation, type BatchResult, ChangePasswordForm, type DataItem, type DeleteResult, type EmailVerificationResult, ForgotPasswordForm, type GitHatConfig, type GitHatContextValue, type GitHatOrg, GitHatProvider, type GitHatUser, type OrgMetadata, OrgSwitcher, type PasswordResetResult, ProtectedRoute, type PutResult, type QueryOptions, type QueryResult, ResetPasswordForm, SignInButton, SignInForm, SignUpButton, type SignUpData, SignUpForm, type SignUpResult, UserButton, VerifiedBadge, VerifyEmailStatus, type VerifyOptions, type WithAuthOptions, useAuth, useData, useGitHat };
|