Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redirect to ticket url path after login (#140) #173

Merged
merged 3 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/src/components/Navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const Navbar = () => {
setLoading(true)
try {
await login()
navigate('/')
//navigate("/") //LoggedInRedirect already does this
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can remove this comment

} catch (err) {
setError('Failed to log in')
console.log(err)
Expand Down
13 changes: 10 additions & 3 deletions frontend/src/contexts/CustomRoutes.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import React from 'react'

Check failure on line 1 in frontend/src/contexts/CustomRoutes.js

View workflow job for this annotation

GitHub Actions / Prettier

frontend/src/contexts/CustomRoutes.js#L1

There are issues with this file's formatting, please run Prettier to fix the errors
import { Navigate, Outlet } from 'react-router-dom'
import { Navigate, Outlet, useLocation } from 'react-router-dom'
import { useAuth } from './AuthContext'

export const PrivateRoute = () => {
const { currentUser } = useAuth()

const location = useLocation()

if (typeof currentUser === 'undefined') return <h1>Loading.....</h1>
if (!currentUser) return <Navigate replace to="/login" />
if (!currentUser) return <Navigate replace to="/login" state = {{from: location.pathname != "/login" ? location.pathname : "/"}}/>
return <Outlet />
}

Expand All @@ -16,6 +18,11 @@

export const LoggedInRedirect = () => {
const { currentUser } = useAuth()
if (currentUser) return <Navigate replace to="/" />

const location = useLocation()

const prevLocation = location.state ? location.state['from'] : "/"

if (currentUser) return <Navigate replace to={prevLocation} />
return <Outlet />
}
Loading