mirror of
https://github.com/myfatemi04/wheelshare-frontend.git
synced 2025-04-16 00:50:18 -04:00
fix authentication issues
This commit is contained in:
parent
b6b1701df9
commit
cb7a6c8d05
|
@ -2,7 +2,6 @@ import { CSSProperties, lazy, Suspense } from 'react';
|
|||
import { BrowserRouter, Route, Switch } from 'react-router-dom';
|
||||
import NotificationsProvider from '../state/Notifications/NotificationsProvider';
|
||||
import { useMe } from './hooks';
|
||||
import UseImmutableTest from './UseImmutableTest';
|
||||
import WheelShare from './WheelShare';
|
||||
import WheelShareLoggedOut from './WheelShareLoggedOut';
|
||||
|
||||
|
@ -25,30 +24,35 @@ export default function App() {
|
|||
const user = useMe();
|
||||
|
||||
return (
|
||||
<NotificationsProvider>
|
||||
<div style={{ padding: '1rem', maxWidth: '100vw' }}>
|
||||
<UseImmutableTest />
|
||||
<div style={style}>
|
||||
<div style={{ padding: '1rem', maxWidth: '100vw' }}>
|
||||
<div style={style}>
|
||||
<Suspense fallback={null}>
|
||||
<BrowserRouter>
|
||||
<Switch>
|
||||
<Route
|
||||
path="/"
|
||||
exact
|
||||
component={user ? WheelShare : WheelShareLoggedOut}
|
||||
/>
|
||||
<Suspense fallback={null}>
|
||||
<Route
|
||||
component={Authenticator}
|
||||
path="/auth/:provider/callback"
|
||||
/>
|
||||
<Route path="/carpools/:id" component={CarpoolPage} />
|
||||
<Route path="/events/:id" component={EventPage} />
|
||||
<Route path="/groups/:id" component={Group} />
|
||||
</Suspense>
|
||||
{user ? (
|
||||
<NotificationsProvider>
|
||||
<Route path="/" exact component={WheelShare} />
|
||||
<Route
|
||||
component={Authenticator}
|
||||
path="/auth/:provider/callback"
|
||||
/>
|
||||
<Route path="/carpools/:id" component={CarpoolPage} />
|
||||
<Route path="/events/:id" component={EventPage} />
|
||||
<Route path="/groups/:id" component={Group} />
|
||||
</NotificationsProvider>
|
||||
) : (
|
||||
<>
|
||||
<WheelShareLoggedOut />
|
||||
<Route
|
||||
component={Authenticator}
|
||||
path="/auth/:provider/callback"
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</Switch>
|
||||
</BrowserRouter>
|
||||
</div>
|
||||
</Suspense>
|
||||
</div>
|
||||
</NotificationsProvider>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -15,7 +15,15 @@ export default function AuthenticationWrapper({
|
|||
const sessionToken = localStorage.getItem('session_token');
|
||||
|
||||
if (sessionToken) {
|
||||
getMe().then(setUser).catch(none);
|
||||
getMe()
|
||||
.then((user) => {
|
||||
if ('status' in user && user.status === 'error') {
|
||||
setUser(null);
|
||||
} else {
|
||||
setUser(user);
|
||||
}
|
||||
})
|
||||
.catch(() => none());
|
||||
} else {
|
||||
none();
|
||||
}
|
||||
|
|
|
@ -75,9 +75,6 @@ export default function Authenticator() {
|
|||
<>
|
||||
<h1>Sign In Error</h1>
|
||||
We couldn't use your Ion account to log in.
|
||||
<br />
|
||||
<br />
|
||||
<a href="/">Home</a>
|
||||
</>
|
||||
);
|
||||
break;
|
||||
|
@ -94,9 +91,6 @@ export default function Authenticator() {
|
|||
children = (
|
||||
<>
|
||||
<h1>Sign In Error</h1>
|
||||
<br />
|
||||
<br />
|
||||
<a href="/">Home</a>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -42,14 +42,12 @@ function InvitationRow({
|
|||
export default function InvitationList() {
|
||||
const { carpool } = useContext(CarpoolContext);
|
||||
|
||||
const eventId = carpool.event.id;
|
||||
|
||||
const [availableSignups, setAvailableSignups] =
|
||||
useImmutable<PotentialInvitee[] | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
getPotentialInvitees(eventId).then(setAvailableSignups);
|
||||
}, [eventId, setAvailableSignups]);
|
||||
getPotentialInvitees(carpool.id).then(setAvailableSignups);
|
||||
}, [carpool.id, setAvailableSignups]);
|
||||
|
||||
const invitedUserIDs = useMemo(
|
||||
() =>
|
||||
|
@ -63,9 +61,11 @@ export default function InvitationList() {
|
|||
|
||||
const availableSignupsAlreadyInvited = useMemo(
|
||||
() =>
|
||||
availableSignups?.filter((signup) =>
|
||||
invitedUserIDs.has(signup.user.id)
|
||||
) ?? null,
|
||||
availableSignups
|
||||
? availableSignups.filter((signup) =>
|
||||
invitedUserIDs.has(signup.user.id)
|
||||
)
|
||||
: null,
|
||||
[availableSignups, invitedUserIDs]
|
||||
);
|
||||
|
||||
|
@ -90,20 +90,26 @@ export default function InvitationList() {
|
|||
>
|
||||
<h1 style={{ marginBottom: '0.25rem' }}>Invite Somebody</h1>
|
||||
{availableSignups === null && 'Loading'}
|
||||
{availableSignupsAlreadyInvited?.map((signup) => (
|
||||
<InvitationRow
|
||||
key={signup.user.id}
|
||||
user={signup.user}
|
||||
isInvited={true}
|
||||
/>
|
||||
))}
|
||||
{availableSignupsNotInvited?.map((signup) => (
|
||||
<InvitationRow
|
||||
key={signup.user.id}
|
||||
user={signup.user}
|
||||
isInvited={false}
|
||||
/>
|
||||
))}
|
||||
{availableSignupsAlreadyInvited?.map(
|
||||
(signup) =>
|
||||
!carpool.members.some(({ id }) => id === signup.user.id) && (
|
||||
<InvitationRow
|
||||
key={signup.user.id}
|
||||
user={signup.user}
|
||||
isInvited={true}
|
||||
/>
|
||||
)
|
||||
)}
|
||||
{availableSignupsNotInvited?.map(
|
||||
(signup) =>
|
||||
!carpool.members.some(({ id }) => id === signup.user.id) && (
|
||||
<InvitationRow
|
||||
key={signup.user.id}
|
||||
user={signup.user}
|
||||
isInvited={false}
|
||||
/>
|
||||
)
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -44,7 +44,13 @@ async function get(path: string) {
|
|||
Authorization: 'Bearer ' + localStorage.getItem('session_token'),
|
||||
},
|
||||
});
|
||||
return await res.json();
|
||||
const result = await res.json();
|
||||
return result;
|
||||
// if (res.ok) {
|
||||
// return result;
|
||||
// } else {
|
||||
// throw new Error(result.message);
|
||||
// }
|
||||
}
|
||||
|
||||
export async function getEventSignups(
|
||||
|
|
Loading…
Reference in New Issue
Block a user