Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix unable to log-in if app is under path #3

Merged
merged 1 commit into from
Jul 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/context/BaseUrlContex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { useContext, createContext, useState } from "react";

const baseUrlContext = createContext();

export function useBaseUrl() {
return useContext(baseUrlContext);
}

export function BaseUrlProvider({ children }) {
const [baseUrl, setBaseUrl] = useState(
"https://localhost:3000"
);

return (
<baseUrlContext.Provider value={[baseUrl, setBaseUrl]}>
{children}
</baseUrlContext.Provider>
);
}
29 changes: 16 additions & 13 deletions src/pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,26 @@ import CustomDrawer from "../components/CustomDrawer";
import Toolbar from "@mui/material/Toolbar";
import CssBaseline from "@mui/material/CssBaseline";
import Box from "@mui/material/Box";
import { BaseUrlProvider } from "../context/BaseUrlContex"

function MyApp({ Component, pageProps }) {
return (
<SessionProvider restorePreviousSession={true}>
<Head>
<title>Solid Calendar</title>
</Head>
<Box sx={{ display: "flex" }}>
<CssBaseline />
<Header title="Solid Calendar" />
<CustomDrawer />
<Box sx={{ flexGrow: 1, pt: 3, pl: 3 }}>
<Toolbar />
<Component {...pageProps} />
<BaseUrlProvider>
<SessionProvider restorePreviousSession={true}>
<Head>
<title>Solid Calendar</title>
</Head>
<Box sx={{ display: "flex" }}>
<CssBaseline />
<Header title="Solid Calendar" />
<CustomDrawer />
<Box sx={{ flexGrow: 1, pt: 3, pl: 3 }}>
<Toolbar />
<Component {...pageProps} />
</Box>
</Box>
</Box>
</SessionProvider>
</SessionProvider>
</BaseUrlProvider>
);
}

Expand Down
6 changes: 6 additions & 0 deletions src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ import { useEffect, useState } from "react";
import { useSession } from "@inrupt/solid-ui-react";
import { getPersonName } from "../utils/participantsHelper";
import { getRDFasJson } from "../utils/fetchHelper";
import { useBaseUrl } from "../context/BaseUrlContex";

export default function Home() {
const { session, sessionRequestInProgress } = useSession();
const [name, setName] = useState("");
const [baseUrl, setBaseUrl] = useBaseUrl();

useEffect(() => {
setBaseUrl(window.location.origin + window.location.pathname);
}, [setBaseUrl]);

useEffect(() => {
const webID = session.info.webId;
Expand Down
9 changes: 3 additions & 6 deletions src/pages/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Container from "@mui/material/Container";
import Stack from "@mui/material/Stack";
import TextField from "@mui/material/TextField";
import Box from "@mui/material/Box";
import { useBaseUrl } from "../context/BaseUrlContex";

const providers = [
{ title: "Inrupt Pod Spaces", url: "https://broker.pod.inrupt.com/" },
Expand All @@ -21,13 +22,9 @@ const providers = [
];

export default function Login() {
const [currentUrl, setCurrentUrl] = useState("https://localhost:3000");
const [baseUrl, setBaseUrl] = useBaseUrl();
const [provider, setProvider] = useState("");

useEffect(() => {
setCurrentUrl(window.location.origin);
}, [setCurrentUrl]);

return (
<div>
<Container maxWidth="sm">
Expand Down Expand Up @@ -78,7 +75,7 @@ export default function Login() {
<LoginButton
authOptions={{ clientName: "solid calendar" }}
oidcIssuer={provider}
redirectUrl={currentUrl}
redirectUrl={baseUrl}
onError={console.error}
>
<Button sx={{ mt: 1 }} variant="outlined">
Expand Down