mirror of
https://github.com/revoltchat/revite.git
synced 2024-12-01 11:20:58 -05:00
fix(invite): allow logged out users to view invites
This commit is contained in:
parent
ce3be17b74
commit
b5077b62ff
4 changed files with 19 additions and 10 deletions
|
@ -7,6 +7,8 @@ import { useClient } from "./RevoltClient";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
auth?: boolean;
|
auth?: boolean;
|
||||||
|
blockRender?: boolean;
|
||||||
|
|
||||||
children: Children;
|
children: Children;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,8 +18,10 @@ export const CheckAuth = (props: Props) => {
|
||||||
const ready = auth.isLoggedIn() && !!client?.user;
|
const ready = auth.isLoggedIn() && !!client?.user;
|
||||||
|
|
||||||
if (props.auth && !ready) {
|
if (props.auth && !ready) {
|
||||||
|
if (props.blockRender) return null;
|
||||||
return <Redirect to="/login" />;
|
return <Redirect to="/login" />;
|
||||||
} else if (!props.auth && ready) {
|
} else if (!props.auth && ready) {
|
||||||
|
if (props.blockRender) return null;
|
||||||
return <Redirect to="/" />;
|
return <Redirect to="/" />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import { observer } from "mobx-react-lite";
|
||||||
|
|
||||||
import { useMemo } from "preact/hooks";
|
import { useMemo } from "preact/hooks";
|
||||||
|
|
||||||
import { useApplicationState } from "../mobx/State";
|
import { useApplicationState } from "../mobx/State";
|
||||||
|
@ -6,8 +8,8 @@ import { AppContext } from "../context/revoltjs/RevoltClient";
|
||||||
|
|
||||||
import { Children } from "../types/Preact";
|
import { Children } from "../types/Preact";
|
||||||
|
|
||||||
export default function FakeClient({ children }: { children: Children }) {
|
export default observer(({ children }: { children: Children }) => {
|
||||||
const config = useApplicationState().config;
|
const config = useApplicationState().config;
|
||||||
const client = useMemo(() => config.createClient(), []);
|
const client = useMemo(() => config.createClient(), [config.get()]);
|
||||||
return <AppContext.Provider value={client}>{children}</AppContext.Provider>;
|
return <AppContext.Provider value={client}>{children}</AppContext.Provider>;
|
||||||
}
|
});
|
||||||
|
|
|
@ -19,7 +19,6 @@ import Channel from "./channels/Channel";
|
||||||
import Developer from "./developer/Developer";
|
import Developer from "./developer/Developer";
|
||||||
import Friends from "./friends/Friends";
|
import Friends from "./friends/Friends";
|
||||||
import Home from "./home/Home";
|
import Home from "./home/Home";
|
||||||
import Invite from "./invite/Invite";
|
|
||||||
import InviteBot from "./invite/InviteBot";
|
import InviteBot from "./invite/InviteBot";
|
||||||
import ChannelSettings from "./settings/ChannelSettings";
|
import ChannelSettings from "./settings/ChannelSettings";
|
||||||
import ServerSettings from "./settings/ServerSettings";
|
import ServerSettings from "./settings/ServerSettings";
|
||||||
|
@ -121,7 +120,6 @@ export default function App() {
|
||||||
<Route path="/friends" component={Friends} />
|
<Route path="/friends" component={Friends} />
|
||||||
<Route path="/open/:id" component={Open} />
|
<Route path="/open/:id" component={Open} />
|
||||||
<Route path="/bot/:id" component={InviteBot} />
|
<Route path="/bot/:id" component={InviteBot} />
|
||||||
<Route path="/invite/:code?" component={Invite} />
|
|
||||||
<Route path="/" component={Home} />
|
<Route path="/" component={Home} />
|
||||||
</Switch>
|
</Switch>
|
||||||
</Routes>
|
</Routes>
|
||||||
|
|
|
@ -31,6 +31,16 @@ export function App() {
|
||||||
<Route path="/login/reset/:token">
|
<Route path="/login/reset/:token">
|
||||||
<Login />
|
<Login />
|
||||||
</Route>
|
</Route>
|
||||||
|
<Route path="/invite/:code">
|
||||||
|
<CheckAuth blockRender>
|
||||||
|
<FakeClient>
|
||||||
|
<Invite />
|
||||||
|
</FakeClient>
|
||||||
|
</CheckAuth>
|
||||||
|
<CheckAuth auth blockRender>
|
||||||
|
<Invite />
|
||||||
|
</CheckAuth>
|
||||||
|
</Route>
|
||||||
<Route path="/login">
|
<Route path="/login">
|
||||||
<CheckAuth>
|
<CheckAuth>
|
||||||
<Login />
|
<Login />
|
||||||
|
@ -41,11 +51,6 @@ export function App() {
|
||||||
<RevoltApp />
|
<RevoltApp />
|
||||||
</CheckAuth>
|
</CheckAuth>
|
||||||
</Route>
|
</Route>
|
||||||
<Route path="/invite/:code">
|
|
||||||
<FakeClient>
|
|
||||||
<Invite />
|
|
||||||
</FakeClient>
|
|
||||||
</Route>
|
|
||||||
</Switch>
|
</Switch>
|
||||||
</Suspense>
|
</Suspense>
|
||||||
</Context>
|
</Context>
|
||||||
|
|
Loading…
Reference in a new issue