Fix routing on redirect to creds page

This commit is contained in:
Neeraj Gupta 2023-03-20 11:00:33 +05:30
parent 7c8739a57b
commit e8d8ffacc9
No known key found for this signature in database
GPG key ID: 3C5A1684DC1729E1
2 changed files with 10 additions and 3 deletions

View file

@ -3,8 +3,11 @@ import OTPDisplay from 'components/Authenicator/OTPDisplay';
import { getAuthCodes } from 'services/authenticator/authenticatorService';
import { Button } from '@mui/material';
import { CustomError } from 'utils/error';
import { PAGES } from 'constants/pages';
import { useRouter } from 'next/router';
const OTPPage = () => {
const router = useRouter();
const [codes, setCodes] = useState([]);
const [searchTerm, setSearchTerm] = useState('');
@ -17,10 +20,12 @@ const OTPPage = () => {
})
.catch((err) => {
if (err.message === CustomError.KEY_MISSING) {
window.location.href = '/';
router.push({
pathname: PAGES.CREDENTIALS,
query: { redirectPage: PAGES.AUTHENICATOR },
});
return;
}
console.error('something wrong here', err);
});
} catch (error) {

View file

@ -30,6 +30,8 @@ import VerifyMasterPasswordForm, {
export default function Credentials() {
const router = useRouter();
const routeReidrectPage =
router.query.redirectPage?.toString() ?? PAGES.GALLERY;
const [keyAttributes, setKeyAttributes] = useState<KeyAttributes>();
const appContext = useContext(AppContext);
const [user, setUser] = useState<User>();
@ -85,7 +87,7 @@ export default function Credentials() {
await decryptAndStoreToken(key);
const redirectURL = appContext.redirectURL;
appContext.setRedirectURL(null);
router.push(redirectURL ?? PAGES.GALLERY);
router.push(redirectURL ?? routeReidrectPage ?? PAGES.GALLERY);
} catch (e) {
logError(e, 'useMasterPassword failed');
}