diff --git a/src/controllers/UsersControllers.ts b/src/controllers/UsersControllers.ts index 08dde7224..665fb2d53 100644 --- a/src/controllers/UsersControllers.ts +++ b/src/controllers/UsersControllers.ts @@ -4,6 +4,7 @@ import { INDEX_FILE } from '../lib/constants'; import { sendError } from '../lib/error/sendError'; import AuthenticationService from '../services/AuthenticationService'; import UsersService from '../services/UsersService'; +import { getRedirect } from './helpers/getRedirect'; class UsersController { constructor( @@ -103,7 +104,7 @@ class UsersController { if (token) { await this.authService.persistToken(token, user.id.toString()); res.cookie('token', token); - res.status(200).json({ token }); + res.status(200).json({ token, redirect: getRedirect(req) }); } } catch (error) { sendError(error); @@ -184,7 +185,7 @@ class UsersController { if (!user) { res.sendFile(INDEX_FILE); } else { - res.redirect('/search'); + res.redirect(getRedirect(req)); } } diff --git a/src/controllers/helpers/getRedirect.ts b/src/controllers/helpers/getRedirect.ts new file mode 100644 index 000000000..c74b0065f --- /dev/null +++ b/src/controllers/helpers/getRedirect.ts @@ -0,0 +1,4 @@ +import { Request } from 'express'; + +export const getRedirect = (req: Request): string => + req.query.redirect?.toString() ?? '/search'; diff --git a/src/lib/misc/getLimitMessage.tsx b/src/lib/misc/getLimitMessage.tsx index 2d7eaf6fb..9baea060e 100644 --- a/src/lib/misc/getLimitMessage.tsx +++ b/src/lib/misc/getLimitMessage.tsx @@ -14,8 +14,8 @@ export const getLimitMessage = () =>