Plant-for-the-Planet-org / treecounter-app

Plant-for-the-Planet App allows you to plant trees with over 100 reforestation projects around the world.
https://www.trilliontreecampaign.org
Other
41 stars 18 forks source link

React web support for Auth0: #1289

Closed crucialfelix closed 3 years ago

crucialfelix commented 5 years ago

Reference app:

https://github.com/auth0-samples/auth0-react-samples/blob/master/01-Login/README.md

auth flow

  1. A user authenticates (login or sign up) by being relocated to a page hosted by auth0
    • web: Clicking Login / Signup
    • apps: immediately relocated to Auth0 page
    • web: visiting any private route will relocate them to Auth0 page, they are returned to private route after authenticating
  2. User signs up or logs in
  3. User is relocated back to trillion trees web OR the react-native app using a registered custom url scheme (eg. trilliontrees://deep-link/url )

Using the AuthProvider from the reference app, we can then get user auth information in any functional component:

  const { user, isAuthenticated, loginWithRedirect, logout } = useAuth0();

https://github.com/auth0-samples/auth0-react-samples/blob/master/01-Login/src/components/NavBar.js https://github.com/auth0-samples/auth0-react-samples/blob/master/01-Login/src/views/Profile.js

Current auth system

Almost all of the current routes and components for authentication will no longer be used. Keep them in place for now, they may be removed in a future PR.

routes

Defined in: web: app/components/App/TreeCounter.js native: app/components/Navigators/AppDrawerNavigator.js

components

redux actions

redux selectors

Changes and Additions

This is wrapped around the main app and allows any functional component to access userProfile with:

  const { user, isAuthenticated, loginWithRedirect, logout } = useAuth0();

Auth0 may need to relocate a user to our domain just so we can relocate them back to auth0. This is for security reasons to prove that we are in control of the domain that will store cookies.

current versions are located: web: app/components/App/TreeCounter.js native: app/components/Navigators/AppDrawerNavigator.js

sagararyal commented 5 years ago

I've added https://accounts.plant-for-the-planet.org as a custom domain in Auth0,

This means instead of calling https://planetapp.eu.auth0.com/

you can call https://accounts.plant-for-the-planet.org

crucialfelix commented 5 years ago

btw. that custom domain you added just relocates to https://plant-for-the-planet.org It is Auth0 doing the relocating so maybe its a configuration issue that I can't find.

sagararyal commented 5 years ago

@crucialfelix

https://planetapp.eu.auth0.com/ redirects to auth0 so https://plant-for-the-planet.org redirects to our home; but

calling api with https://accounts.plant-for-the-planet.org

like: https://planetapp.eu.auth0.com/api/v2/ should be fine.

Screen Shot 2019-09-27 at 11 11 54 AM