mirror of
https://github.com/myfatemi04/wheelshare-frontend.git
synced 2025-04-21 11:20:17 -04:00
Add redirect url to authentication process
This commit is contained in:
parent
1fbbf5904a
commit
567b8e0901
|
@ -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);
|
||||||
})
|
})
|
||||||
|
|
|
@ -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',
|
||||||
},
|
},
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user