Add redirect url to authentication process

This commit is contained in:
Michael Fatemi 2021-07-06 22:26:57 -04:00
parent 1fbbf5904a
commit 567b8e0901
4 changed files with 16 additions and 6 deletions

View File

@ -12,6 +12,13 @@ function useCodeAndError() {
return [code, error]; return [code, error];
} }
function inferRedirectUrl() {
// Strip query parameters
const { protocol, host, pathname } = window.location;
const redirectUrl = `${protocol}//${host}${pathname}`;
return redirectUrl;
}
export default function Authenticator() { export default function Authenticator() {
const { provider } = useParams<{ provider: string }>(); const { provider } = useParams<{ provider: string }>();
const [code, error] = useCodeAndError(); const [code, error] = useCodeAndError();
@ -31,7 +38,7 @@ export default function Authenticator() {
useEffect(() => { useEffect(() => {
if (code) { if (code) {
setPending(true); setPending(true);
createSession(code) createSession(code, inferRedirectUrl())
.then(({ token }) => { .then(({ token }) => {
setToken(token ?? null); setToken(token ?? null);
}) })

View File

@ -1,7 +1,7 @@
export async function createSession(code: string) { export async function createSession(code: string, redirectUrl: string) {
const res = await fetch('http://localhost:5000/create_session', { const res = await fetch('http://localhost:5000/create_session', {
method: 'post', method: 'post',
body: JSON.stringify({ code }), body: JSON.stringify({ code, redirectUrl }),
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
}, },

View File

@ -1,7 +1,7 @@
import { ICarpool, IUser } from './types'; import { ICarpool } from './types';
import UISecondaryBox from './UISecondaryBox'; import UISecondaryBox from './UISecondaryBox';
function MemberList({ members }: { members: IUser[] }) { function MemberList({ members }: { members: ICarpool['members'] }) {
return ( return (
<div style={{ display: 'flex', flexDirection: 'column' }}> <div style={{ display: 'flex', flexDirection: 'column' }}>
{members.length > 0 {members.length > 0

View File

@ -29,7 +29,10 @@ export type ICarpool = {
description: string; description: string;
eventId: number | null; eventId: number | null;
event?: IEvent; event?: IEvent;
members: IUser[]; members: {
id: number;
name: string;
}[];
invitations: IInvitation[]; invitations: IInvitation[];
}; };