Skip to content

Commit

Permalink
Fix navigation to support base href
Browse files Browse the repository at this point in the history
  • Loading branch information
mpgxvii committed Oct 3, 2024
1 parent 20e62f6 commit 3548a82
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 20 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ dist/
cypress/videos
cypress/screenshots

.idea
.idea
.env
3 changes: 0 additions & 3 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ const GlobalStyle = createGlobalStyle((props: ThemeProps) =>
function MyApp({ Component, pageProps }: AppProps) {
return (
<div data-testid="app-react">
<Head>
<base href="/kratos-ui/" />
</Head>
<ThemeProvider theme={theme}>
<GlobalStyle />
<Component {...pageProps} />
Expand Down
21 changes: 11 additions & 10 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const Home: NextPage = () => {
const [hasSession, setHasSession] = useState<boolean>(false)
const router = useRouter()
const onLogout = LogoutLink()
const handleNavigation = (href: string) => () => router.push(href)

useEffect(() => {
ory
Expand Down Expand Up @@ -60,62 +61,62 @@ const Home: NextPage = () => {
<div className="row">
<DocsButton
testid="study"
href="/study?projectId=STAGING_PROJECT"
disabled={hasSession}
title={"Study"}
onClick={handleNavigation("/study?projectId=STAGING_PROJECT")}
/>
<DocsButton
testid="eligibility"
href="/eligibility"
disabled={hasSession}
title={"Eligibility"}
onClick={handleNavigation("/eligibility")}
/>
<DocsButton
testid="login"
href="/login"
disabled={hasSession}
title={"Login"}
onClick={handleNavigation("/login")}
/>
<DocsButton
testid="sign-up"
href="/registration"
disabled={hasSession}
title={"Sign Up"}
onClick={handleNavigation("/registration")}
/>
<DocsButton
testid="recover-account"
href="/recovery"
disabled={hasSession}
title="Recover Account"
onClick={handleNavigation("/recovery")}
/>
<DocsButton
testid="verify-account"
href="/verification"
title="Verify Account"
onClick={handleNavigation("/verification")}
/>
<DocsButton
testid="consent"
href="/study-consent"
title="Study Consent"
disabled={!hasSession}
onClick={handleNavigation("/study-consent")}
/>
<DocsButton
testid="apps"
href="/apps"
title="Apps"
disabled={!hasSession}
onClick={handleNavigation("/apps")}
/>
<DocsButton
testid="profile"
href="/profile"
title="Profile"
disabled={!hasSession}
onClick={handleNavigation("/profile")}
/>
<DocsButton
testid="account-settings"
href="/settings"
disabled={!hasSession}
title={"Account Settings"}
onClick={handleNavigation("/settings")}
/>
<DocsButton
testid="logout"
Expand Down
4 changes: 2 additions & 2 deletions pkg/sdk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { Configuration, FrontendApi } from "@ory/client"
import { edgeConfig } from "@ory/integrations/next"

const localConfig = {
basePath: process.env.NEXT_PUBLIC_KRATOS_PUBLIC_URL ?? "" + "/api/.ory",
basePath: `${process.env.NEXT_PUBLIC_KRATOS_PUBLIC_URL}/api/.ory`,
baseOptions: {
withCredentials: true,
},
}

export default new FrontendApi(
new Configuration(
process.env.NEXT_PUBLIC_KRATOS_PUBLIC_URL ? localConfig : edgeConfig,
localConfig,
),
)
5 changes: 1 addition & 4 deletions pkg/styled/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import {
import cn from "classnames"
import styled from "styled-components"

const BASE_URL = process.env.BASE_PATH || ""

export const MarginCard = styled(Card)`
margin-top: 70px;
margin-bottom: 18px;
Expand Down Expand Up @@ -109,15 +107,14 @@ export const DocsButton = ({
disabled,
unresponsive,
}: DocsButtonProps) => {
const url = BASE_URL + href
return (
<div className={cn("col-xs-4", { "col-md-12": !unresponsive })}>
<div className="box">
<TextLeftButton
onClick={onClick}
disabled={disabled}
data-testid={testid}
href={url}
href={href}
>
{title}
</TextLeftButton>
Expand Down

0 comments on commit 3548a82

Please sign in to comment.