@@ -2,10 +2,33 @@ import React from 'react';
22import { BrowserRouter } from 'react-router-dom' ;
33import { AuthorizerProvider } from '@authorizerdev/authorizer-react' ;
44import Root from './Root' ;
5+ import { createRandomString } from './utils/common' ;
56
67export default function App ( ) {
7- // @ts -ignore
8- const globalState : Record < string , string > = window [ '__authorizer__' ] ;
8+ const searchParams = new URLSearchParams ( window . location . search ) ;
9+ const state = searchParams . get ( 'state' ) || createRandomString ( ) ;
10+ const scope = searchParams . get ( 'scope' )
11+ ? searchParams . get ( 'scope' ) ?. toString ( ) . split ( ' ' )
12+ : `openid profile email` ;
13+
14+ const urlProps : Record < string , any > = {
15+ state,
16+ scope,
17+ } ;
18+
19+ const redirectURL =
20+ searchParams . get ( 'redirect_uri' ) || searchParams . get ( 'redirectURL' ) ;
21+ if ( redirectURL ) {
22+ urlProps . redirectURL = redirectURL ;
23+ } else {
24+ urlProps . redirectURL = window . location . origin ;
25+ }
26+ const globalState : Record < string , string > = {
27+ // @ts -ignore
28+ ...window [ '__authorizer__' ] ,
29+ ...urlProps ,
30+ } ;
31+
932 return (
1033 < div
1134 style = { {
@@ -30,23 +53,15 @@ export default function App() {
3053 />
3154 < h1 > { globalState . organizationName } </ h1 >
3255 </ div >
33- < div
34- style = { {
35- width : 400 ,
36- margin : `10px auto` ,
37- border : `1px solid #D1D5DB` ,
38- padding : `25px 20px` ,
39- borderRadius : 5 ,
40- } }
41- >
56+ < div className = "container" >
4257 < BrowserRouter >
4358 < AuthorizerProvider
4459 config = { {
4560 authorizerURL : window . location . origin ,
4661 redirectURL : globalState . redirectURL ,
4762 } }
4863 >
49- < Root />
64+ < Root globalState = { globalState } />
5065 </ AuthorizerProvider >
5166 </ BrowserRouter >
5267 </ div >
0 commit comments