From 62633aed174871494d259a5df6d592f994415539 Mon Sep 17 00:00:00 2001 From: Michael Fatemi Date: Thu, 8 Jul 2021 12:23:42 -0400 Subject: [PATCH] make authorization endpoint's redirect url react to window location --- .env | 2 +- .../Authentication/authorizationEndpoint.ts | 15 +++++++++++++ src/components/WheelShareLoggedOut.tsx | 21 ++----------------- 3 files changed, 18 insertions(+), 20 deletions(-) create mode 100644 src/components/Authentication/authorizationEndpoint.ts diff --git a/.env b/.env index f4f9697..e9e2be3 100644 --- a/.env +++ b/.env @@ -1,2 +1,2 @@ -REACT_APP_API_ENDPOINT_0=http://localhost:5000/api +REACT_APP_API_DOMAIN_=http://localhost:5000/ REACT_APP_API_DOMAIN=https://wheelshare-altbackend-2efyw.ondigitalocean.app/ diff --git a/src/components/Authentication/authorizationEndpoint.ts b/src/components/Authentication/authorizationEndpoint.ts new file mode 100644 index 0000000..663b0a5 --- /dev/null +++ b/src/components/Authentication/authorizationEndpoint.ts @@ -0,0 +1,15 @@ +function createAuthorizationEndpoint(redirectUrl: string) { + const url = new URL('https://ion.tjhsst.edu/oauth/authorize'); + + url.searchParams.set('response_type', 'code'); + url.searchParams.set('client_id', 'rNa6n9YSg8ftINdyVPpUsaMuxNbHLo9dh1OsOktR'); + url.searchParams.set('redirect_uri', redirectUrl); + url.searchParams.set('scope', 'read'); + + return url.toString(); +} + +const redirectUrl = `${window.location.protocol}://${window.location.host}/auth/ion/callback`; +const authorizationEndpoint = createAuthorizationEndpoint(redirectUrl); + +export default authorizationEndpoint; diff --git a/src/components/WheelShareLoggedOut.tsx b/src/components/WheelShareLoggedOut.tsx index b1655d4..a5e0213 100644 --- a/src/components/WheelShareLoggedOut.tsx +++ b/src/components/WheelShareLoggedOut.tsx @@ -1,30 +1,13 @@ +import authorizationEndpoint from './Authentication/authorizationEndpoint'; import UILink from './UILink'; import UIPrimaryTitle from './UIPrimaryTitle'; -function createAuthorizationEndpoint(redirectUrl: string) { - const url = new URL('https://ion.tjhsst.edu/oauth/authorize'); - - url.searchParams.set('response_type', 'code'); - url.searchParams.set('client_id', 'rNa6n9YSg8ftINdyVPpUsaMuxNbHLo9dh1OsOktR'); - url.searchParams.set('redirect_uri', redirectUrl); - url.searchParams.set('scope', 'read'); - - return url.toString(); -} - -const dev = true; -const endpoint = createAuthorizationEndpoint( - dev - ? 'http://localhost:3000/auth/ion/callback' - : 'https://wheelshare.space/auth/ion/callback' -); - export default function WheelShareLoggedOut() { return ( <> WheelShare

To get started, log in with your Ion account.

- Log in + Log in ); }