mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-04-25 11:59:11 +00:00
feat(web): add machinery/new-session
This commit is contained in:
parent
9c2a6a8d61
commit
2ab13f134e
5 changed files with 34 additions and 1 deletions
|
@ -4,6 +4,7 @@ import * as React from 'react';
|
|||
const LandingPage = React.lazy(() => import('../pages/landing'));
|
||||
const DevToolsSetApi = React.lazy(() => import('../pages/dev-tools/set-api'));
|
||||
const DevToolsSessionDebug = React.lazy(() => import('../pages/dev-tools/session-debug'));
|
||||
const MachineryNewSession = React.lazy(() => import('../pages/machinery/new-session'));
|
||||
|
||||
const RouteWrapper = (props: {
|
||||
component: React.LazyExoticComponent<React.ComponentType<any>>;
|
||||
|
@ -19,6 +20,7 @@ export const AppRouter = () => {
|
|||
return (
|
||||
<Router>
|
||||
<RouteWrapper component={LandingPage} path="/" />
|
||||
<RouteWrapper component={MachineryNewSession} path="/machinery/new-session" />
|
||||
<RouteWrapper component={DevToolsSetApi} path="/x/dev-tools/set-api" />
|
||||
<RouteWrapper
|
||||
component={DevToolsSessionDebug}
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
import { useApiContext } from '../../api-context/ApiContext';
|
||||
import { useSessionContext } from '../../session-context/SessionContext';
|
||||
|
||||
const SessionDebug = () => {
|
||||
const session = useSessionContext();
|
||||
const api = useApiContext();
|
||||
|
||||
return (
|
||||
<pre>
|
||||
{JSON.stringify(
|
||||
{
|
||||
isAuthenticated: !!session.session?.user,
|
||||
apiUrl: api.apiUrl,
|
||||
isAuthenticated: session.isAuthenticated,
|
||||
user: session.session?.user || null,
|
||||
guilds: session.session?.guilds || null,
|
||||
},
|
||||
|
|
|
@ -1,7 +1,16 @@
|
|||
import { Redirect } from '@reach/router';
|
||||
import { LandingTemplate } from '@roleypoly/design-system/templates/landing';
|
||||
import * as React from 'react';
|
||||
import { useSessionContext } from '../session-context/SessionContext';
|
||||
|
||||
const Landing = () => {
|
||||
const { isAuthenticated } = useSessionContext();
|
||||
|
||||
if (isAuthenticated) {
|
||||
// return <Redirect to="/servers" />;
|
||||
return <Redirect to="/x/dev-tools/session-debug" />;
|
||||
}
|
||||
|
||||
return <LandingTemplate />;
|
||||
};
|
||||
|
||||
|
|
16
packages/web/src/pages/machinery/new-session.tsx
Normal file
16
packages/web/src/pages/machinery/new-session.tsx
Normal file
|
@ -0,0 +1,16 @@
|
|||
import * as React from 'react';
|
||||
|
||||
const NewSession = () => {
|
||||
React.useEffect(() => {
|
||||
const url = new URL(window.location.href);
|
||||
const id = url.searchParams.get('session_id');
|
||||
if (id) {
|
||||
window.location.href = '/';
|
||||
localStorage.setItem('rp_session_key', id);
|
||||
}
|
||||
});
|
||||
|
||||
return <div>Redirecting you...</div>;
|
||||
};
|
||||
|
||||
export default NewSession;
|
|
@ -6,9 +6,11 @@ type SessionContextT = {
|
|||
session?: Omit<Partial<SessionData>, 'tokens'>;
|
||||
setSession: (session?: SessionContextT['session']) => void;
|
||||
authedFetch: (url: string, opts?: RequestInit) => Promise<Response>;
|
||||
isAuthenticated: boolean;
|
||||
};
|
||||
|
||||
const SessionContext = React.createContext<SessionContextT>({
|
||||
isAuthenticated: false,
|
||||
setSession: () => {},
|
||||
authedFetch: async () => {
|
||||
return new Response();
|
||||
|
@ -36,6 +38,7 @@ export const SessionContextProvider = (props: { children: React.ReactNode }) =>
|
|||
},
|
||||
});
|
||||
},
|
||||
isAuthenticated: !!session && !!session.sessionID && !!session.user,
|
||||
}),
|
||||
[session, api]
|
||||
);
|
||||
|
|
Loading…
Add table
Reference in a new issue