Skip to content

Commit

Permalink
fix: update login redirect URL in getLimitMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
aalemayhu committed Jul 22, 2023
1 parent eb3d399 commit 58f2460
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/controllers/UsersControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -184,7 +185,7 @@ class UsersController {
if (!user) {
res.sendFile(INDEX_FILE);
} else {
res.redirect('/search');
res.redirect(getRedirect(req));
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/controllers/helpers/getRedirect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Request } from 'express';

export const getRedirect = (req: Request): string =>
req.query.redirect?.toString() ?? '/search';
4 changes: 2 additions & 2 deletions src/lib/misc/getLimitMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ export const getLimitMessage = () =>
</li>
<li>
<a href="https://alemayhu.com/patreon">Become a patron</a> to remove
the limit or <a href="/login">login</a> if you already have an
account.
the limit or <a href="/login?redirect=/upload">login</a> if you
already have an account.
</li>
</ul>
</>
Expand Down

0 comments on commit 58f2460

Please sign in to comment.