Skip to content

Commit 3d89508

Browse files
authored
fix(ui): reincorporate basePath into logout component link (#7451)
## Description Fixes issue where the `basePath` from the `next-config` was not respected for the `logout` button link - [x] I have read and understand the [CONTRIBUTING.md](https://github.com/payloadcms/payload/blob/main/CONTRIBUTING.md) document in this repository. ## Type of change - [x] Bug fix (non-breaking change which fixes an issue) ## Checklist: - [x] Existing test suite passes locally with my changes
1 parent b160686 commit 3d89508

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

packages/ui/src/elements/Logout/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const DefaultLogout: React.FC<{
2323
routes: { admin: adminRoute },
2424
} = config
2525

26+
const basePath = process.env.NEXT_BASE_PATH ?? ''
2627
const LinkElement = Link || 'a'
2728

2829
return (
@@ -31,6 +32,7 @@ const DefaultLogout: React.FC<{
3132
className={`${baseClass}__log-out`}
3233
href={formatAdminURL({
3334
adminRoute,
35+
basePath,
3436
path: logoutRoute,
3537
})}
3638
tabIndex={tabIndex}

packages/ui/src/utilities/formatAdminURL.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@ import type { Config } from 'payload'
33
/** Will read the `routes.admin` config and appropriately handle `"/"` admin paths */
44
export const formatAdminURL = (args: {
55
adminRoute: Config['routes']['admin']
6+
basePath?: string
67
path: string
78
serverURL?: Config['serverURL']
89
}): string => {
9-
const { adminRoute, path, serverURL } = args
10+
const { adminRoute, basePath = '', path, serverURL } = args
1011

1112
if (adminRoute) {
1213
if (adminRoute === '/') {
1314
if (!path) {
14-
return `${serverURL || ''}${adminRoute}`
15+
return `${serverURL || ''}${basePath}${adminRoute}`
1516
}
1617
} else {
17-
return `${serverURL || ''}${adminRoute}${path}`
18+
return `${serverURL || ''}${basePath}${adminRoute}${path}`
1819
}
1920
}
2021

21-
return `${serverURL || ''}${path}`
22+
return `${serverURL || ''}${basePath}${path}`
2223
}

0 commit comments

Comments
 (0)