fix(invite): allow logged out users to view invites

This commit is contained in:
Paul Makles 2021-12-28 12:24:35 +00:00
parent ce3be17b74
commit b5077b62ff
4 changed files with 19 additions and 10 deletions

View file

@ -7,6 +7,8 @@ import { useClient } from "./RevoltClient";
interface Props {
auth?: boolean;
blockRender?: boolean;
children: Children;
}
@ -16,8 +18,10 @@ export const CheckAuth = (props: Props) => {
const ready = auth.isLoggedIn() && !!client?.user;
if (props.auth && !ready) {
if (props.blockRender) return null;
return <Redirect to="/login" />;
} else if (!props.auth && ready) {
if (props.blockRender) return null;
return <Redirect to="/" />;
}

View file

@ -1,3 +1,5 @@
import { observer } from "mobx-react-lite";
import { useMemo } from "preact/hooks";
import { useApplicationState } from "../mobx/State";
@ -6,8 +8,8 @@ import { AppContext } from "../context/revoltjs/RevoltClient";
import { Children } from "../types/Preact";
export default function FakeClient({ children }: { children: Children }) {
export default observer(({ children }: { children: Children }) => {
const config = useApplicationState().config;
const client = useMemo(() => config.createClient(), []);
const client = useMemo(() => config.createClient(), [config.get()]);
return <AppContext.Provider value={client}>{children}</AppContext.Provider>;
}
});

View file

@ -19,7 +19,6 @@ import Channel from "./channels/Channel";
import Developer from "./developer/Developer";
import Friends from "./friends/Friends";
import Home from "./home/Home";
import Invite from "./invite/Invite";
import InviteBot from "./invite/InviteBot";
import ChannelSettings from "./settings/ChannelSettings";
import ServerSettings from "./settings/ServerSettings";
@ -121,7 +120,6 @@ export default function App() {
<Route path="/friends" component={Friends} />
<Route path="/open/:id" component={Open} />
<Route path="/bot/:id" component={InviteBot} />
<Route path="/invite/:code?" component={Invite} />
<Route path="/" component={Home} />
</Switch>
</Routes>

View file

@ -31,6 +31,16 @@ export function App() {
<Route path="/login/reset/:token">
<Login />
</Route>
<Route path="/invite/:code">
<CheckAuth blockRender>
<FakeClient>
<Invite />
</FakeClient>
</CheckAuth>
<CheckAuth auth blockRender>
<Invite />
</CheckAuth>
</Route>
<Route path="/login">
<CheckAuth>
<Login />
@ -41,11 +51,6 @@ export function App() {
<RevoltApp />
</CheckAuth>
</Route>
<Route path="/invite/:code">
<FakeClient>
<Invite />
</FakeClient>
</Route>
</Switch>
</Suspense>
</Context>