Skip to content

Commit

Permalink
Remove login route (#750)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggrossetie authored Jan 16, 2023
1 parent 0ac3bc6 commit 17eb05a
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion front/src/components/Articles.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Field from './Field'
import Loading from './Loading'
import { Search, Users } from 'react-feather'
import ArticleTag from './Tag'
import Select from "./Select";
import Select from './Select'

export default function Articles () {
const dispatch = useDispatch()
Expand Down
2 changes: 1 addition & 1 deletion front/src/components/Login.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useCallback, useState, useEffect } from 'react'
import { Link, useHistory } from 'react-router-dom'
import { useSelector, useDispatch } from 'react-redux'
import { useSelector, useDispatch, shallowEqual } from 'react-redux'

import styles from './login.module.scss'
import Field from './Field'
Expand Down
6 changes: 3 additions & 3 deletions front/src/components/UserInfos.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ export default function UserInfos () {
const activeUser = useSelector(state => state.activeUser, shallowEqual)
const sessionToken = useSelector(state => state.sessionToken)
const [displayName, setDisplayName] = useState(activeUser.displayName)
const [firstName, setFirstName] = useState(activeUser.firstName)
const [lastName, setLastName] = useState(activeUser.lastName)
const [institution, setInstitution] = useState(activeUser.institution)
const [firstName, setFirstName] = useState(activeUser.firstName || '')
const [lastName, setLastName] = useState(activeUser.lastName || '')
const [institution, setInstitution] = useState(activeUser.institution || '')
const [yaml, setYaml] = useState(activeUser.yaml)
const [isSaving, setIsSaving] = useState(false)

Expand Down
4 changes: 0 additions & 4 deletions front/src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import Field from './components/Field'
import { Check, Copy, Search } from 'react-feather'
import buttonStyles from './components/button.module.scss'
import Select from './components/Select'
import Login from './components/Login.jsx'

// lazy loaded routes
const Books = lazy(() => import('./components/Books'))
Expand Down Expand Up @@ -92,9 +91,6 @@ render(
<Route path="/register" exact>
<Register />
</Route>
<Route path="/login" exact>
<Login />
</Route>
{/* Articles index */}
<PrivateRoute path={['/articles', '/']} exact>
<Articles />
Expand Down
14 changes: 13 additions & 1 deletion front/src/layouts/App.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
import React, { Suspense, useCallback, useEffect } from 'react'
import { useSelector } from 'react-redux'
import { useDispatch, useSelector } from 'react-redux'

import Loading from '../components/Loading'
import { useHistory } from "react-router-dom";

export default function StyloApp ({ children }) {
const hasBooted = useSelector(state => state.hasBooted)
const dispatch = useDispatch()
const { replace, location } = useHistory()
const setSessionToken = useCallback((token) => dispatch({ type: 'UPDATE_SESSION_TOKEN', token }), [])
const authToken = new URLSearchParams(location.hash).get('#auth-token')

useEffect(() => {
if (authToken) {
setSessionToken(authToken)
replace(location.pathname)
}
}, [authToken])

return (
<main>
Expand Down
4 changes: 2 additions & 2 deletions graphql/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ app.get(
if (req.user) {
const { email } = req.user
const token = await createJWTToken({ email, jwtSecret })
res.redirect(`${req.headers.referer}/login#auth-token=${token}`)
res.redirect(`${req.headers.referer}#auth-token=${token}`)
} else {
req.session.origin = req.headers.referer
next()
Expand Down Expand Up @@ -232,7 +232,7 @@ app.use('/authorization-code/callback',
async function onSuccess (req, res) {
const { email } = req.user
const token = await createJWTToken({ email, jwtSecret })
return res.redirect(`${req.session.origin}/login#auth-token=${token}`)
return res.redirect(`${req.session.origin}#auth-token=${token}`)
},
function onFailure (error, req, res) {
logger.error({ error }, 'Unexpected error.')
Expand Down

0 comments on commit 17eb05a

Please sign in to comment.