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];
}
function inferRedirectUrl() {
// Strip query parameters
const { protocol, host, pathname } = window.location;
const redirectUrl = `${protocol}//${host}${pathname}`;
return redirectUrl;
}
export default function Authenticator() {
const { provider } = useParams<{ provider: string }>();
const [code, error] = useCodeAndError();
@ -31,7 +38,7 @@ export default function Authenticator() {
useEffect(() => {
if (code) {
setPending(true);
createSession(code)
createSession(code, inferRedirectUrl())
.then(({ token }) => {
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', {
method: 'post',
body: JSON.stringify({ code }),
body: JSON.stringify({ code, redirectUrl }),
headers: {
'Content-Type': 'application/json',
},

View File

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

View File

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