Skip to content

Commit 33055d1

Browse files
committed
fix:cli url path
1 parent fb995e2 commit 33055d1

8 files changed

Lines changed: 67 additions & 28 deletions

File tree

api/controller/device_auth_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func (dc *DeviceAuthController) RequestCode(c *gin.Context) {
4949
return
5050
}
5151

52-
resp, err := dc.DeviceAuthUsecase.RequestCode(c, request, "/device")
52+
resp, err := dc.DeviceAuthUsecase.RequestCode(c, request, "/auth/device")
5353
if err != nil {
5454
c.JSON(http.StatusInternalServerError, domain.RespError(err.Error()))
5555
return

cli/cmd/auth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ var loginCmd = &cobra.Command{
7979
func resolveVerificationURI(serverURL, verificationURI string) string {
8080
uri := strings.TrimSpace(verificationURI)
8181
if uri == "" {
82-
uri = "/device"
82+
uri = "/auth/device"
8383
}
8484
if parsed, err := url.Parse(uri); err == nil && parsed.IsAbs() {
8585
return uri

cli/cmd/auth_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package cmd
2+
3+
import "testing"
4+
5+
func TestResolveVerificationURI(t *testing.T) {
6+
tests := []struct {
7+
name string
8+
serverURL string
9+
verificationURI string
10+
want string
11+
}{
12+
{
13+
name: "empty falls back to auth device path",
14+
serverURL: "http://localhost:55667",
15+
verificationURI: "",
16+
want: "http://localhost:55667/auth/device",
17+
},
18+
{
19+
name: "relative path resolved against server",
20+
serverURL: "http://localhost:55667/",
21+
verificationURI: "/auth/device",
22+
want: "http://localhost:55667/auth/device",
23+
},
24+
{
25+
name: "absolute uri unchanged",
26+
serverURL: "http://localhost:55667",
27+
verificationURI: "https://shadmin.example.com/auth/device",
28+
want: "https://shadmin.example.com/auth/device",
29+
},
30+
}
31+
32+
for _, tt := range tests {
33+
t.Run(tt.name, func(t *testing.T) {
34+
if got := resolveVerificationURI(tt.serverURL, tt.verificationURI); got != tt.want {
35+
t.Fatalf("resolveVerificationURI() = %q, want %q", got, tt.want)
36+
}
37+
})
38+
}
39+
}

docs/cli-api规范.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ CLI ──POST /api/v1/auth/device/code──► 后端
8888
8989
用户看到:
9090
📋 授权码: WDJB-MJHT
91-
🔗 访问: http://your-shadmin/device
91+
🔗 访问: http://your-shadmin/auth/device
9292
9393
CLI ──轮询 /api/v1/auth/device/token──► 后端(每5s)
9494
◄── authorization_pending ─────── (用户未确认)
@@ -107,7 +107,7 @@ POST /api/v1/auth/device/token
107107
Response: { access_token, refresh_token } | { error: "authorization_pending" }
108108
```
109109

110-
**前端需新增授权页** `/device`:输入 `user_code` → 确认授权。
110+
**前端需新增授权页** `/auth/device`:输入 `user_code` → 确认授权。
111111

112112
**CLI 实现要点**`cli/cmd/auth.go`):
113113
```go

web/src/components/layout/authenticated-layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function AuthenticatedLayout({ children }: AuthenticatedLayoutProps) {
1515
const defaultOpen = getCookie('sidebar_state') !== 'false'
1616
const location = useLocation()
1717

18-
if (location.pathname === '/device') {
18+
if (location.pathname === '/auth/device') {
1919
return children ?? <Outlet />
2020
}
2121

web/src/routeTree.gen.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import { Route as rootRouteImport } from './routes/__root'
1212
import { Route as AuthenticatedRouteRouteImport } from './routes/_authenticated/route'
1313
import { Route as AuthenticatedIndexRouteImport } from './routes/_authenticated/index'
14-
import { Route as AuthenticatedDeviceRouteImport } from './routes/_authenticated/device'
1514
import { Route as errors503RouteImport } from './routes/(errors)/503'
1615
import { Route as errors500RouteImport } from './routes/(errors)/500'
1716
import { Route as errors404RouteImport } from './routes/(errors)/404'
@@ -36,6 +35,7 @@ import { Route as AuthenticatedSystemApiResourcesRouteImport } from './routes/_a
3635
import { Route as AuthenticatedSettingsAppearanceRouteImport } from './routes/_authenticated/settings/appearance'
3736
import { Route as AuthenticatedSettingsAccountRouteImport } from './routes/_authenticated/settings/account'
3837
import { Route as AuthenticatedErrorsErrorRouteImport } from './routes/_authenticated/errors/$error'
38+
import { Route as AuthenticatedAuthDeviceRouteImport } from './routes/_authenticated/auth/device'
3939

4040
const AuthenticatedRouteRoute = AuthenticatedRouteRouteImport.update({
4141
id: '/_authenticated',
@@ -46,11 +46,6 @@ const AuthenticatedIndexRoute = AuthenticatedIndexRouteImport.update({
4646
path: '/',
4747
getParentRoute: () => AuthenticatedRouteRoute,
4848
} as any)
49-
const AuthenticatedDeviceRoute = AuthenticatedDeviceRouteImport.update({
50-
id: '/device',
51-
path: '/device',
52-
getParentRoute: () => AuthenticatedRouteRoute,
53-
} as any)
5449
const errors503Route = errors503RouteImport.update({
5550
id: '/(errors)/503',
5651
path: '/503',
@@ -179,6 +174,11 @@ const AuthenticatedErrorsErrorRoute =
179174
path: '/errors/$error',
180175
getParentRoute: () => AuthenticatedRouteRoute,
181176
} as any)
177+
const AuthenticatedAuthDeviceRoute = AuthenticatedAuthDeviceRouteImport.update({
178+
id: '/auth/device',
179+
path: '/auth/device',
180+
getParentRoute: () => AuthenticatedRouteRoute,
181+
} as any)
182182

183183
export interface FileRoutesByFullPath {
184184
'/': typeof AuthenticatedIndexRoute
@@ -192,7 +192,7 @@ export interface FileRoutesByFullPath {
192192
'/404': typeof errors404Route
193193
'/500': typeof errors500Route
194194
'/503': typeof errors503Route
195-
'/device': typeof AuthenticatedDeviceRoute
195+
'/auth/device': typeof AuthenticatedAuthDeviceRoute
196196
'/errors/$error': typeof AuthenticatedErrorsErrorRoute
197197
'/settings/account': typeof AuthenticatedSettingsAccountRoute
198198
'/settings/appearance': typeof AuthenticatedSettingsAppearanceRoute
@@ -218,8 +218,8 @@ export interface FileRoutesByTo {
218218
'/404': typeof errors404Route
219219
'/500': typeof errors500Route
220220
'/503': typeof errors503Route
221-
'/device': typeof AuthenticatedDeviceRoute
222221
'/': typeof AuthenticatedIndexRoute
222+
'/auth/device': typeof AuthenticatedAuthDeviceRoute
223223
'/errors/$error': typeof AuthenticatedErrorsErrorRoute
224224
'/settings/account': typeof AuthenticatedSettingsAccountRoute
225225
'/settings/appearance': typeof AuthenticatedSettingsAppearanceRoute
@@ -248,8 +248,8 @@ export interface FileRoutesById {
248248
'/(errors)/404': typeof errors404Route
249249
'/(errors)/500': typeof errors500Route
250250
'/(errors)/503': typeof errors503Route
251-
'/_authenticated/device': typeof AuthenticatedDeviceRoute
252251
'/_authenticated/': typeof AuthenticatedIndexRoute
252+
'/_authenticated/auth/device': typeof AuthenticatedAuthDeviceRoute
253253
'/_authenticated/errors/$error': typeof AuthenticatedErrorsErrorRoute
254254
'/_authenticated/settings/account': typeof AuthenticatedSettingsAccountRoute
255255
'/_authenticated/settings/appearance': typeof AuthenticatedSettingsAppearanceRoute
@@ -279,7 +279,7 @@ export interface FileRouteTypes {
279279
| '/404'
280280
| '/500'
281281
| '/503'
282-
| '/device'
282+
| '/auth/device'
283283
| '/errors/$error'
284284
| '/settings/account'
285285
| '/settings/appearance'
@@ -305,8 +305,8 @@ export interface FileRouteTypes {
305305
| '/404'
306306
| '/500'
307307
| '/503'
308-
| '/device'
309308
| '/'
309+
| '/auth/device'
310310
| '/errors/$error'
311311
| '/settings/account'
312312
| '/settings/appearance'
@@ -334,8 +334,8 @@ export interface FileRouteTypes {
334334
| '/(errors)/404'
335335
| '/(errors)/500'
336336
| '/(errors)/503'
337-
| '/_authenticated/device'
338337
| '/_authenticated/'
338+
| '/_authenticated/auth/device'
339339
| '/_authenticated/errors/$error'
340340
| '/_authenticated/settings/account'
341341
| '/_authenticated/settings/appearance'
@@ -381,13 +381,6 @@ declare module '@tanstack/react-router' {
381381
preLoaderRoute: typeof AuthenticatedIndexRouteImport
382382
parentRoute: typeof AuthenticatedRouteRoute
383383
}
384-
'/_authenticated/device': {
385-
id: '/_authenticated/device'
386-
path: '/device'
387-
fullPath: '/device'
388-
preLoaderRoute: typeof AuthenticatedDeviceRouteImport
389-
parentRoute: typeof AuthenticatedRouteRoute
390-
}
391384
'/(errors)/503': {
392385
id: '/(errors)/503'
393386
path: '/503'
@@ -556,6 +549,13 @@ declare module '@tanstack/react-router' {
556549
preLoaderRoute: typeof AuthenticatedErrorsErrorRouteImport
557550
parentRoute: typeof AuthenticatedRouteRoute
558551
}
552+
'/_authenticated/auth/device': {
553+
id: '/_authenticated/auth/device'
554+
path: '/auth/device'
555+
fullPath: '/auth/device'
556+
preLoaderRoute: typeof AuthenticatedAuthDeviceRouteImport
557+
parentRoute: typeof AuthenticatedRouteRoute
558+
}
559559
}
560560
}
561561

@@ -579,8 +579,8 @@ const AuthenticatedSettingsRouteRouteWithChildren =
579579

580580
interface AuthenticatedRouteRouteChildren {
581581
AuthenticatedSettingsRouteRoute: typeof AuthenticatedSettingsRouteRouteWithChildren
582-
AuthenticatedDeviceRoute: typeof AuthenticatedDeviceRoute
583582
AuthenticatedIndexRoute: typeof AuthenticatedIndexRoute
583+
AuthenticatedAuthDeviceRoute: typeof AuthenticatedAuthDeviceRoute
584584
AuthenticatedErrorsErrorRoute: typeof AuthenticatedErrorsErrorRoute
585585
AuthenticatedSystemApiResourcesRoute: typeof AuthenticatedSystemApiResourcesRoute
586586
AuthenticatedSystemDictRoute: typeof AuthenticatedSystemDictRoute
@@ -596,8 +596,8 @@ interface AuthenticatedRouteRouteChildren {
596596

597597
const AuthenticatedRouteRouteChildren: AuthenticatedRouteRouteChildren = {
598598
AuthenticatedSettingsRouteRoute: AuthenticatedSettingsRouteRouteWithChildren,
599-
AuthenticatedDeviceRoute: AuthenticatedDeviceRoute,
600599
AuthenticatedIndexRoute: AuthenticatedIndexRoute,
600+
AuthenticatedAuthDeviceRoute: AuthenticatedAuthDeviceRoute,
601601
AuthenticatedErrorsErrorRoute: AuthenticatedErrorsErrorRoute,
602602
AuthenticatedSystemApiResourcesRoute: AuthenticatedSystemApiResourcesRoute,
603603
AuthenticatedSystemDictRoute: AuthenticatedSystemDictRoute,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createFileRoute } from '@tanstack/react-router'
22
import { DeviceActivate } from '@/features/auth/device-activate'
33

4-
export const Route = createFileRoute('/_authenticated/device')({
4+
export const Route = createFileRoute('/_authenticated/auth/device')({
55
component: DeviceActivate,
66
})

web/src/routes/_authenticated/route.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useAuthStore } from '@/stores/auth-store'
44
import { AuthenticatedLayout } from '@/components/layout/authenticated-layout'
55

66
// Routes that are always accessible for authenticated users (not menu-managed)
7-
const ALWAYS_ALLOWED_PATHS = ['/', '/settings', '/errors', '/device']
7+
const ALWAYS_ALLOWED_PATHS = ['/', '/settings', '/errors', '/auth/device']
88

99
export const Route = createFileRoute('/_authenticated')({
1010
beforeLoad: async ({ location }) => {

0 commit comments

Comments
 (0)