1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-01-26 18:58:21 +02:00

Server: Fixes #9367: Redirect user from login to home if already logged (#9415)

This commit is contained in:
pedr 2023-11-30 10:39:49 -03:00 committed by GitHub
parent 2fd985b9ac
commit 3ee8da0cae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 1 deletions

View File

@ -72,4 +72,38 @@ describe('index_login', () => {
}
});
test('should redirect if already logged in', async () => {
const user = await createUser(1);
const context = await doLogin(user.email, '123456');
const sessionId = cookieGet(context, 'sessionId');
const getContext = await koaAppContext({
sessionId: sessionId,
request: {
method: 'GET',
url: '/login',
},
});
await routeHandler(getContext);
expect(getContext.response.status).toBe(302);
});
test('should not redirect if sessionId is not valid', async () => {
const getContext = await koaAppContext({
sessionId: 'no-sense',
request: {
method: 'GET',
url: '/login',
},
});
await routeHandler(getContext);
expect(getContext.response.status).toBe(200);
});
});

View File

@ -8,6 +8,7 @@ import defaultView from '../../utils/defaultView';
import { View } from '../../services/MustacheService';
import limiterLoginBruteForce from '../../utils/request/limiterLoginBruteForce';
import { cookieSet } from '../../utils/cookies';
import { homeUrl } from '../../utils/urlUtils';
function makeView(error: any = null): View {
const view = defaultView('login', 'Login');
@ -22,7 +23,10 @@ const router: Router = new Router(RouteType.Web);
router.public = true;
router.get('login', async (_path: SubPath, _ctx: AppContext) => {
router.get('login', async (_path: SubPath, ctx: AppContext) => {
if (ctx.joplin.owner) {
return redirect(ctx, homeUrl());
}
return makeView();
});