Compare commits

...

3 Commits

Author SHA1 Message Date
Y
f76408ba51 Merge pull request 'issue-47' (#59) from issue-47 into main
Some checks failed
Release / build_and_release (push) Failing after 33s
Reviewed-on: https://git.sigit.io/sig/it/pulls/59
Reviewed-by: Y <yury@4gl.io>
2024-05-17 13:39:01 +00:00
Davinci
a1f16c33b2 style: lint 2024-05-17 15:28:47 +02:00
Davinci
eff8827a86 fix: opening link to sign a file while not logged in is not redirecting correctly 2024-05-17 15:28:35 +02:00
2 changed files with 29 additions and 17 deletions

View File

@ -33,6 +33,14 @@ const App = () => {
} }
} }
const handleRootRedirect = () => {
if (authState.loggedIn) return appPrivateRoutes.homePage
const callbackPathEncoded = btoa(
window.location.href.split(`${window.location.origin}/#`)[1]
)
return `${appPublicRoutes.login}?callbackPath=${callbackPathEncoded}`
}
return ( return (
<Routes> <Routes>
<Route element={<MainLayout />}> <Route element={<MainLayout />}>
@ -66,18 +74,7 @@ const App = () => {
} }
})} })}
<Route <Route path="*" element={<Navigate to={handleRootRedirect()} />} />
path="*"
element={
<Navigate
to={
authState.loggedIn
? appPrivateRoutes.homePage
: appPublicRoutes.login
}
/>
}
/>
</Route> </Route>
</Routes> </Routes>
) )

View File

@ -2,7 +2,7 @@ import { Box, Button, TextField, Typography } from '@mui/material'
import { getPublicKey, nip19 } from 'nostr-tools' import { getPublicKey, nip19 } from 'nostr-tools'
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
import { useDispatch } from 'react-redux' import { useDispatch } from 'react-redux'
import { useNavigate } from 'react-router-dom' import { useNavigate, useSearchParams } from 'react-router-dom'
import { toast } from 'react-toastify' import { toast } from 'react-toastify'
import { LoadingSpinner } from '../../components/LoadingSpinner' import { LoadingSpinner } from '../../components/LoadingSpinner'
import { import {
@ -22,6 +22,8 @@ import { npubToHex, queryNip05 } from '../../utils'
import styles from './style.module.scss' import styles from './style.module.scss'
export const Login = () => { export const Login = () => {
const [searchParams] = useSearchParams()
const dispatch: Dispatch = useDispatch() const dispatch: Dispatch = useDispatch()
const navigate = useNavigate() const navigate = useNavigate()
@ -53,6 +55,19 @@ export const Login = () => {
} }
} }
const navigateAfterLogin = (path: string) => {
const callbackPath = searchParams.get('callbackPath')
if (callbackPath) {
// base64 decoded path
const path = atob(callbackPath)
navigate(path)
return
}
navigate(path)
}
const loginWithExtension = async () => { const loginWithExtension = async () => {
setIsLoading(true) setIsLoading(true)
setLoadingSpinnerDesc('Capturing pubkey from nostr extension') setLoadingSpinnerDesc('Capturing pubkey from nostr extension')
@ -66,7 +81,7 @@ export const Login = () => {
const redirectPath = const redirectPath =
await authController.authenticateAndFindMetadata(pubkey) await authController.authenticateAndFindMetadata(pubkey)
navigate(redirectPath) navigateAfterLogin(redirectPath)
}) })
.catch((err) => { .catch((err) => {
toast.error('Error capturing public key from nostr extension: ' + err) toast.error('Error capturing public key from nostr extension: ' + err)
@ -109,7 +124,7 @@ export const Login = () => {
return null return null
}) })
if (redirectPath) navigate(redirectPath) if (redirectPath) navigateAfterLogin(redirectPath)
setIsLoading(false) setIsLoading(false)
setLoadingSpinnerDesc('') setLoadingSpinnerDesc('')
@ -204,7 +219,7 @@ export const Login = () => {
return null return null
}) })
if (redirectPath) navigate(redirectPath) if (redirectPath) navigateAfterLogin(redirectPath)
}) })
.catch((err) => { .catch((err) => {
toast.error( toast.error(
@ -264,7 +279,7 @@ export const Login = () => {
return null return null
}) })
if (redirectPath) navigate(redirectPath) if (redirectPath) navigateAfterLogin(redirectPath)
}) })
.catch((err) => { .catch((err) => {
toast.error( toast.error(