@checkstack/auth-frontend 0.1.0 → 0.3.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/CHANGELOG.md CHANGED
@@ -1,5 +1,160 @@
1
1
  # @checkstack/auth-frontend
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 7a23261: ## TanStack Query Integration
8
+
9
+ Migrated all frontend components to use `usePluginClient` hook with TanStack Query integration, replacing the legacy `forPlugin()` pattern.
10
+
11
+ ### New Features
12
+
13
+ - **`usePluginClient` hook**: Provides type-safe access to plugin APIs with `.useQuery()` and `.useMutation()` methods
14
+ - **Automatic request deduplication**: Multiple components requesting the same data share a single network request
15
+ - **Built-in caching**: Configurable stale time and cache duration per query
16
+ - **Loading/error states**: TanStack Query provides `isLoading`, `error`, `isRefetching` states automatically
17
+ - **Background refetching**: Stale data is automatically refreshed when components mount
18
+
19
+ ### Contract Changes
20
+
21
+ All RPC contracts now require `operationType: "query"` or `operationType: "mutation"` metadata:
22
+
23
+ ```typescript
24
+ const getItems = proc()
25
+ .meta({ operationType: "query", access: [access.read] })
26
+ .output(z.array(itemSchema))
27
+ .query();
28
+
29
+ const createItem = proc()
30
+ .meta({ operationType: "mutation", access: [access.manage] })
31
+ .input(createItemSchema)
32
+ .output(itemSchema)
33
+ .mutation();
34
+ ```
35
+
36
+ ### Migration
37
+
38
+ ```typescript
39
+ // Before (forPlugin pattern)
40
+ const api = useApi(myPluginApiRef);
41
+ const [items, setItems] = useState<Item[]>([]);
42
+ useEffect(() => {
43
+ api.getItems().then(setItems);
44
+ }, [api]);
45
+
46
+ // After (usePluginClient pattern)
47
+ const client = usePluginClient(MyPluginApi);
48
+ const { data: items, isLoading } = client.getItems.useQuery({});
49
+ ```
50
+
51
+ ### Bug Fixes
52
+
53
+ - Fixed `rpc.test.ts` test setup for middleware type inference
54
+ - Fixed `SearchDialog` to use `setQuery` instead of deprecated `search` method
55
+ - Fixed null→undefined warnings in notification and queue frontends
56
+
57
+ ### Patch Changes
58
+
59
+ - Updated dependencies [7a23261]
60
+ - @checkstack/frontend-api@0.2.0
61
+ - @checkstack/common@0.3.0
62
+ - @checkstack/auth-common@0.3.0
63
+ - @checkstack/ui@0.2.1
64
+
65
+ ## 0.2.0
66
+
67
+ ### Minor Changes
68
+
69
+ - 9faec1f: # Unified AccessRule Terminology Refactoring
70
+
71
+ This release completes a comprehensive terminology refactoring from "permission" to "accessRule" across the entire codebase, establishing a consistent and modern access control vocabulary.
72
+
73
+ ## Changes
74
+
75
+ ### Core Infrastructure (`@checkstack/common`)
76
+
77
+ - Introduced `AccessRule` interface as the primary access control type
78
+ - Added `accessPair()` helper for creating read/manage access rule pairs
79
+ - Added `access()` builder for individual access rules
80
+ - Replaced `Permission` type with `AccessRule` throughout
81
+
82
+ ### API Changes
83
+
84
+ - `env.registerPermissions()` → `env.registerAccessRules()`
85
+ - `meta.permissions` → `meta.access` in RPC contracts
86
+ - `usePermission()` → `useAccess()` in frontend hooks
87
+ - Route `permission:` field → `accessRule:` field
88
+
89
+ ### UI Changes
90
+
91
+ - "Roles & Permissions" tab → "Roles & Access Rules"
92
+ - "You don't have permission..." → "You don't have access..."
93
+ - All permission-related UI text updated
94
+
95
+ ### Documentation & Templates
96
+
97
+ - Updated 18 documentation files with AccessRule terminology
98
+ - Updated 7 scaffolding templates with `accessPair()` pattern
99
+ - All code examples use new AccessRule API
100
+
101
+ ## Migration Guide
102
+
103
+ ### Backend Plugins
104
+
105
+ ```diff
106
+ - import { permissionList } from "./permissions";
107
+ - env.registerPermissions(permissionList);
108
+ + import { accessRules } from "./access";
109
+ + env.registerAccessRules(accessRules);
110
+ ```
111
+
112
+ ### RPC Contracts
113
+
114
+ ```diff
115
+ - .meta({ userType: "user", permissions: [permissions.read.id] })
116
+ + .meta({ userType: "user", access: [access.read] })
117
+ ```
118
+
119
+ ### Frontend Hooks
120
+
121
+ ```diff
122
+ - const canRead = accessApi.usePermission(permissions.read.id);
123
+ + const canRead = accessApi.useAccess(access.read);
124
+ ```
125
+
126
+ ### Routes
127
+
128
+ ```diff
129
+ - permission: permissions.entityRead.id,
130
+ + accessRule: access.read,
131
+ ```
132
+
133
+ ### Patch Changes
134
+
135
+ - 95eeec7: # Auto-login after credential registration
136
+
137
+ Users are now automatically logged in after successful registration when using the credential (email & password) authentication strategy.
138
+
139
+ ## Changes
140
+
141
+ ### Backend (`@checkstack/auth-backend`)
142
+
143
+ - Added `autoSignIn: true` to the `emailAndPassword` configuration in better-auth
144
+ - Users no longer need to manually log in after registration; a session is created immediately upon successful sign-up
145
+
146
+ ### Frontend (`@checkstack/auth-frontend`)
147
+
148
+ - Updated `RegisterPage` to use full page navigation after registration to ensure the session state refreshes correctly
149
+ - Updated `LoginPage` to use full page navigation after login to ensure fresh permissions state when switching between users
150
+
151
+ - Updated dependencies [9faec1f]
152
+ - Updated dependencies [f533141]
153
+ - @checkstack/auth-common@0.2.0
154
+ - @checkstack/common@0.2.0
155
+ - @checkstack/frontend-api@0.1.0
156
+ - @checkstack/ui@0.2.0
157
+
3
158
  ## 0.1.0
4
159
 
5
160
  ### Minor Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@checkstack/auth-frontend",
3
- "version": "0.1.0",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "main": "src/index.tsx",
6
6
  "exports": {
package/src/api.ts CHANGED
@@ -25,10 +25,10 @@ export interface Role {
25
25
  description?: string | null;
26
26
  isSystem?: boolean;
27
27
  isAssignable?: boolean; // False for anonymous role - not assignable to users
28
- permissions?: string[];
28
+ accessRules?: string[];
29
29
  }
30
30
 
31
- export interface Permission {
31
+ export interface AccessRuleEntry {
32
32
  id: string;
33
33
  description?: string;
34
34
  }
@@ -1,4 +1,4 @@
1
- import React, { useState, useEffect } from "react";
1
+ import React, { useState } from "react";
2
2
  import {
3
3
  Card,
4
4
  CardHeader,
@@ -25,8 +25,7 @@ import {
25
25
  useToast,
26
26
  } from "@checkstack/ui";
27
27
  import { Plus, Trash2, RotateCcw, Copy } from "lucide-react";
28
- import { useApi } from "@checkstack/frontend-api";
29
- import { rpcApiRef } from "@checkstack/frontend-api";
28
+ import { usePluginClient } from "@checkstack/frontend-api";
30
29
  import { AuthApi } from "@checkstack/auth-common";
31
30
  import type { Role } from "../api";
32
31
 
@@ -49,12 +48,9 @@ export const ApplicationsTab: React.FC<ApplicationsTabProps> = ({
49
48
  roles,
50
49
  canManageApplications,
51
50
  }) => {
52
- const rpcApi = useApi(rpcApiRef);
53
- const authClient = rpcApi.forPlugin(AuthApi);
51
+ const authClient = usePluginClient(AuthApi);
54
52
  const toast = useToast();
55
53
 
56
- const [applications, setApplications] = useState<Application[]>([]);
57
- const [loading, setLoading] = useState(true);
58
54
  const [applicationToDelete, setApplicationToDelete] = useState<string>();
59
55
  const [applicationToRegenerateSecret, setApplicationToRegenerateSecret] =
60
56
  useState<{ id: string; name: string }>();
@@ -67,36 +63,19 @@ export const ApplicationsTab: React.FC<ApplicationsTabProps> = ({
67
63
  const [newAppName, setNewAppName] = useState("");
68
64
  const [newAppDescription, setNewAppDescription] = useState("");
69
65
 
70
- const fetchApplications = async () => {
71
- if (!canManageApplications) {
72
- setLoading(false);
73
- return;
74
- }
75
- setLoading(true);
76
- try {
77
- const data = await authClient.getApplications();
78
- setApplications(data as Application[]);
79
- } catch (error) {
80
- console.error("Failed to fetch applications:", error);
81
- } finally {
82
- setLoading(false);
83
- }
84
- };
85
-
86
- useEffect(() => {
87
- fetchApplications();
88
- }, [canManageApplications]);
66
+ // Query: Applications list
67
+ const {
68
+ data: applications = [],
69
+ isLoading: loading,
70
+ refetch: refetchApplications,
71
+ } = authClient.getApplications.useQuery(
72
+ {},
73
+ { enabled: canManageApplications }
74
+ );
89
75
 
90
- const handleCreateApplication = async () => {
91
- if (!newAppName.trim()) {
92
- toast.error("Application name is required");
93
- return;
94
- }
95
- try {
96
- const result = await authClient.createApplication({
97
- name: newAppName.trim(),
98
- description: newAppDescription.trim() || undefined,
99
- });
76
+ // Mutations
77
+ const createApplicationMutation = authClient.createApplication.useMutation({
78
+ onSuccess: (result) => {
100
79
  setCreateAppDialogOpen(false);
101
80
  setNewAppName("");
102
81
  setNewAppDescription("");
@@ -105,15 +84,68 @@ export const ApplicationsTab: React.FC<ApplicationsTabProps> = ({
105
84
  secret: result.secret,
106
85
  applicationName: result.application.name,
107
86
  });
108
- await fetchApplications();
109
- } catch (error: unknown) {
87
+ void refetchApplications();
88
+ },
89
+ onError: (error) => {
110
90
  toast.error(
111
91
  error instanceof Error ? error.message : "Failed to create application"
112
92
  );
93
+ },
94
+ });
95
+
96
+ const updateApplicationMutation = authClient.updateApplication.useMutation({
97
+ onSuccess: () => {
98
+ void refetchApplications();
99
+ },
100
+ onError: (error) => {
101
+ toast.error(
102
+ error instanceof Error ? error.message : "Failed to update application"
103
+ );
104
+ },
105
+ });
106
+
107
+ const deleteApplicationMutation = authClient.deleteApplication.useMutation({
108
+ onSuccess: () => {
109
+ toast.success("Application deleted successfully");
110
+ setApplicationToDelete(undefined);
111
+ void refetchApplications();
112
+ },
113
+ onError: (error) => {
114
+ toast.error(
115
+ error instanceof Error ? error.message : "Failed to delete application"
116
+ );
117
+ },
118
+ });
119
+
120
+ const regenerateSecretMutation =
121
+ authClient.regenerateApplicationSecret.useMutation({
122
+ onSuccess: (result) => {
123
+ setNewSecretDialog({
124
+ open: true,
125
+ secret: result.secret,
126
+ applicationName: applicationToRegenerateSecret?.name ?? "",
127
+ });
128
+ setApplicationToRegenerateSecret(undefined);
129
+ },
130
+ onError: (error) => {
131
+ toast.error(
132
+ error instanceof Error ? error.message : "Failed to regenerate secret"
133
+ );
134
+ },
135
+ });
136
+
137
+ const handleCreateApplication = () => {
138
+ if (!newAppName.trim()) {
139
+ toast.error("Application name is required");
140
+ return;
113
141
  }
142
+ createApplicationMutation.mutate({
143
+ name: newAppName.trim(),
144
+ description: newAppDescription.trim() || undefined,
145
+ });
114
146
  };
115
147
 
116
- const handleToggleApplicationRole = async (
148
+ const handleToggleApplicationRole = (
117
149
  appId: string,
118
150
  roleId: string,
119
151
  currentRoles: string[]
@@ -122,56 +154,20 @@ export const ApplicationsTab: React.FC<ApplicationsTabProps> = ({
122
154
  ? currentRoles.filter((r) => r !== roleId)
123
155
  : [...currentRoles, roleId];
124
156
 
125
- try {
126
- await authClient.updateApplication({
127
- id: appId,
128
- roles: newRoles,
129
- });
130
- setApplications(
131
- applications.map((a) =>
132
- a.id === appId ? { ...a, roles: newRoles } : a
133
- )
134
- );
135
- } catch (error: unknown) {
136
- toast.error(
137
- error instanceof Error
138
- ? error.message
139
- : "Failed to update application roles"
140
- );
141
- }
157
+ updateApplicationMutation.mutate({
158
+ id: appId,
159
+ roles: newRoles,
160
+ });
142
161
  };
143
162
 
144
- const handleDeleteApplication = async () => {
163
+ const handleDeleteApplication = () => {
145
164
  if (!applicationToDelete) return;
146
- try {
147
- await authClient.deleteApplication(applicationToDelete);
148
- toast.success("Application deleted successfully");
149
- setApplicationToDelete(undefined);
150
- await fetchApplications();
151
- } catch (error: unknown) {
152
- toast.error(
153
- error instanceof Error ? error.message : "Failed to delete application"
154
- );
155
- }
165
+ deleteApplicationMutation.mutate(applicationToDelete);
156
166
  };
157
167
 
158
- const handleRegenerateSecret = async () => {
168
+ const handleRegenerateSecret = () => {
159
169
  if (!applicationToRegenerateSecret) return;
160
- try {
161
- const result = await authClient.regenerateApplicationSecret(
162
- applicationToRegenerateSecret.id
163
- );
164
- setApplicationToRegenerateSecret(undefined);
165
- setNewSecretDialog({
166
- open: true,
167
- secret: result.secret,
168
- applicationName: applicationToRegenerateSecret.name,
169
- });
170
- } catch (error: unknown) {
171
- toast.error(
172
- error instanceof Error ? error.message : "Failed to regenerate secret"
173
- );
174
- }
170
+ regenerateSecretMutation.mutate(applicationToRegenerateSecret.id);
175
171
  };
176
172
 
177
173
  return (
@@ -199,7 +195,7 @@ export const ApplicationsTab: React.FC<ApplicationsTabProps> = ({
199
195
  <div className="flex justify-center py-4">
200
196
  <LoadingSpinner />
201
197
  </div>
202
- ) : applications.length === 0 ? (
198
+ ) : (applications as Application[]).length === 0 ? (
203
199
  <p className="text-muted-foreground">
204
200
  No external applications configured yet.
205
201
  </p>
@@ -214,7 +210,7 @@ export const ApplicationsTab: React.FC<ApplicationsTabProps> = ({
214
210
  </TableRow>
215
211
  </TableHeader>
216
212
  <TableBody>
217
- {applications.map((app) => (
213
+ {(applications as Application[]).map((app) => (
218
214
  <TableRow key={app.id}>
219
215
  <TableCell>
220
216
  <div className="flex flex-col">
@@ -303,7 +299,7 @@ export const ApplicationsTab: React.FC<ApplicationsTabProps> = ({
303
299
 
304
300
  {!canManageApplications && (
305
301
  <p className="text-xs text-muted-foreground mt-4">
306
- You don't have permission to manage applications.
302
+ You don't have access to manage applications.
307
303
  </p>
308
304
  )}
309
305
  </CardContent>
@@ -322,7 +318,7 @@ export const ApplicationsTab: React.FC<ApplicationsTabProps> = ({
322
318
  <ConfirmationModal
323
319
  isOpen={!!applicationToRegenerateSecret}
324
320
  onClose={() => setApplicationToRegenerateSecret(undefined)}
325
- onConfirm={() => void handleRegenerateSecret()}
321
+ onConfirm={handleRegenerateSecret}
326
322
  title="Regenerate Application Secret"
327
323
  message={`Are you sure you want to regenerate the secret for "${
328
324
  applicationToRegenerateSecret?.name ?? ""
@@ -365,7 +361,7 @@ export const ApplicationsTab: React.FC<ApplicationsTabProps> = ({
365
361
  variant="outline"
366
362
  size="sm"
367
363
  onClick={() => {
368
- navigator.clipboard.writeText(newSecretDialog.secret);
364
+ void navigator.clipboard.writeText(newSecretDialog.secret);
369
365
  toast.success("Secret copied to clipboard");
370
366
  }}
371
367
  >
@@ -448,8 +444,11 @@ export const ApplicationsTab: React.FC<ApplicationsTabProps> = ({
448
444
  >
449
445
  Cancel
450
446
  </Button>
451
- <Button onClick={() => void handleCreateApplication()}>
452
- Create
447
+ <Button
448
+ onClick={handleCreateApplication}
449
+ disabled={createApplicationMutation.isPending}
450
+ >
451
+ {createApplicationMutation.isPending ? "Creating..." : "Create"}
453
452
  </Button>
454
453
  </DialogFooter>
455
454
  </DialogContent>