@@ -15,20 +15,27 @@ import { ResetPassword, resetPasswordBaseClass } from '../ResetPassword/index.js
15
15
import { UnauthorizedView } from '../Unauthorized/index.js'
16
16
import { Verify , verifyBaseClass } from '../Verify/index.js'
17
17
import { getCustomViewByRoute } from './getCustomViewByRoute.js'
18
+ import { isPathMatchingRoute } from './isPathMatchingRoute.js'
18
19
19
20
const baseClasses = {
21
+ account : 'account' ,
20
22
forgot : forgotPasswordBaseClass ,
21
23
login : loginBaseClass ,
22
24
reset : resetPasswordBaseClass ,
23
25
verify : verifyBaseClass ,
24
26
}
25
27
26
- const oneSegmentViews = {
27
- 'create-first-user' : CreateFirstUserView ,
28
+ type OneSegmentViews = {
29
+ [ K in keyof SanitizedConfig [ 'admin' ] [ 'routes' ] ] : AdminViewComponent
30
+ }
31
+
32
+ const oneSegmentViews : OneSegmentViews = {
33
+ account : Account ,
34
+ createFirstUser : CreateFirstUserView ,
28
35
forgot : ForgotPasswordView ,
36
+ inactivity : LogoutInactivity ,
29
37
login : LoginView ,
30
38
logout : LogoutView ,
31
- 'logout-inactivity' : LogoutInactivity ,
32
39
unauthorized : UnauthorizedView ,
33
40
}
34
41
@@ -78,22 +85,41 @@ export const getViewFromConfig = ({
78
85
break
79
86
}
80
87
case 1 : {
81
- if ( oneSegmentViews [ segmentOne ] && segmentOne !== 'account' ) {
88
+ // users can override the default routes via `admin.routes` config
89
+ // i.e.{ admin: { routes: { logout: '/sign-out', inactivity: '/idle' }}}
90
+ let viewToRender : keyof typeof oneSegmentViews
91
+
92
+ if ( config . admin . routes ) {
93
+ const matchedRoute = Object . entries ( config . admin . routes ) . find ( ( [ , route ] ) => {
94
+ return isPathMatchingRoute ( {
95
+ currentRoute,
96
+ exact : true ,
97
+ path : `${ adminRoute } ${ route } ` ,
98
+ } )
99
+ } )
100
+
101
+ if ( matchedRoute ) {
102
+ viewToRender = matchedRoute [ 0 ] as keyof typeof oneSegmentViews
103
+ }
104
+ }
105
+
106
+ if ( oneSegmentViews [ viewToRender ] ) {
107
+ // --> /account
82
108
// --> /create-first-user
83
109
// --> /forgot
84
110
// --> /login
85
111
// --> /logout
86
112
// --> /logout-inactivity
87
113
// --> /unauthorized
88
- ViewToRender = oneSegmentViews [ segmentOne ]
89
- templateClassName = baseClasses [ segmentOne ]
114
+
115
+ ViewToRender = oneSegmentViews [ viewToRender ]
116
+ templateClassName = baseClasses [ viewToRender ]
90
117
templateType = 'minimal'
91
- } else if ( segmentOne === 'account' ) {
92
- // --> /account
93
- initPageOptions . redirectUnauthenticatedUser = true
94
- ViewToRender = Account
95
- templateClassName = 'account'
96
- templateType = 'default'
118
+
119
+ if ( viewToRender === 'account' ) {
120
+ initPageOptions . redirectUnauthenticatedUser = true
121
+ templateType = 'default'
122
+ }
97
123
}
98
124
break
99
125
}
0 commit comments