Skip to content

Commit

Permalink
Merge branch 'dev' into check-itinerary-existence
Browse files Browse the repository at this point in the history
  • Loading branch information
binh-dam-ibigroup committed Oct 29, 2020
2 parents b0831d1 + 98186fd commit 1cbc87a
Show file tree
Hide file tree
Showing 21 changed files with 912 additions and 453 deletions.
3 changes: 3 additions & 0 deletions __tests__/reducers/__snapshots__/create-otp-reducer.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ Object {
"debouncePlanTimeMs": 0,
"homeTimezone": "America/Los_Angeles",
"language": Object {},
"phoneFormatOptions": Object {
"countryCode": "US",
},
"realtimeEffectsDisplayThreshold": 120,
"routingTypes": Array [],
"stopViewer": Object {
Expand Down
5 changes: 5 additions & 0 deletions example-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,8 @@ itinerary:
# modes:
# - WALK
# - BICYCLE

### If using OTP Middleware, you can define the optional phone number options below.
# phoneFormatOptions:
# # ISO 2-letter country code for phone number formats (defaults to 'US')
# countryCode: US
36 changes: 14 additions & 22 deletions lib/actions/auth.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { push } from 'connected-react-router'
import { replace, push } from 'connected-react-router'

import { setPathBeforeSignIn } from '../actions/user'

Expand Down Expand Up @@ -30,30 +30,22 @@ export function showLoginError (err) {
/**
* This function is called by the Auth0Provider component, with the described parameter(s),
* after the user signs in.
* @param {Object} appState The state that was stored when calling useAuth().login().
* @param {Object} appState The state stored when calling useAuth0().loginWithRedirect
* or when instantiating a component that uses withAuhenticationRequired.
*/
export function processSignIn (appState) {
return function (dispatch, getState) {
if (appState && appState.urlHash) {
// At this stage after login, Auth0 has already redirected to /signedin (Auth0-whitelisted)
// which shows the AfterLoginScreen.
//
// Here, we save the URL hash prior to login (contains a combination of itinerary search, stop/trip view, etc.),
// so that the AfterLoginScreen can redirect back there when logged-in user info is fetched.
// (For routing, it is easier to deal with the path without the hash sign.)
const hashIndex = appState.urlHash.indexOf('#')
const urlHashWithoutHash = hashIndex >= 0
? appState.urlHash.substr(hashIndex + 1)
: '/'
dispatch(setPathBeforeSignIn(urlHashWithoutHash))
} else if (appState && appState.returnTo) {
// TODO: Handle other after-login situations.
// Note that when redirecting from a login-protected (e.g. account) page while logged out,
// then returnTo is set by Auth0 to this object format:
// {
// pathname: "/"
// query: { ... }
// }
if (appState && appState.returnTo) {
// Remove URL parameters that were added by auth0-react
// (see https://github.com/auth0/auth0-react/blob/adac2e810d4f6d33253cb8b2016fcedb98a3bc16/examples/cra-react-router/src/index.tsx#L7).
window.history.replaceState({}, '', window.location.pathname)

// Here, we add the hash to the redux state (portion of the URL after '#' that contains the route/page name e.g. /account,
// and includes a combination of itinerary search, stop/trip view, etc.) that was passed to appState.returnTo prior to login.
// Once the redux state set, we redirect to the "/signedin" route (whitelisted in Auth0 dashboard), where the AfterLoginScreen
// will in turn fetch the user data then redirect the web browser back to appState.returnTo.
dispatch(setPathBeforeSignIn(appState.returnTo))
dispatch(replace('/signedin'))
}
}
}
Loading

0 comments on commit 1cbc87a

Please sign in to comment.