mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2025-12-19 18:18:27 -05:00
fix(api): stop redirecting after signout (#64616)
This commit is contained in:
committed by
GitHub
parent
3bdf64b4e7
commit
50a85f6683
@@ -1,6 +1,5 @@
|
|||||||
import { describe, it, expect, beforeEach } from 'vitest';
|
import { describe, it, expect, beforeEach } from 'vitest';
|
||||||
import { devLogin, setupServer, superRequest } from '../../../vitest.utils.js';
|
import { devLogin, setupServer, superRequest } from '../../../vitest.utils.js';
|
||||||
import { HOME_LOCATION } from '../../utils/env.js';
|
|
||||||
|
|
||||||
describe('GET /signout', () => {
|
describe('GET /signout', () => {
|
||||||
setupServer();
|
setupServer();
|
||||||
@@ -29,12 +28,9 @@ describe('GET /signout', () => {
|
|||||||
expect(setCookie).toHaveLength(3);
|
expect(setCookie).toHaveLength(3);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should redirect to / on the client by default', async () => {
|
it('should respond with an empty object', async () => {
|
||||||
const res = await superRequest('/signout', { method: 'GET' });
|
const res = await superRequest('/signout', { method: 'GET' });
|
||||||
|
expect(res.body).toEqual({});
|
||||||
// TODO: separate the validation and normalization logic.
|
expect(res.status).toBe(200);
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
||||||
expect(res.headers.location).toBe(`${HOME_LOCATION}/`);
|
|
||||||
expect(res.status).toBe(302);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { FastifyPluginCallback } from 'fastify';
|
import type { FastifyPluginCallback } from 'fastify';
|
||||||
|
|
||||||
import { getRedirectParams } from '../../utils/redirection.js';
|
import { signout } from '../../schemas.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Route handler for signing out.
|
* Route handler for signing out.
|
||||||
@@ -15,13 +15,19 @@ export const signoutRoute: FastifyPluginCallback = (
|
|||||||
_options,
|
_options,
|
||||||
done
|
done
|
||||||
) => {
|
) => {
|
||||||
fastify.get('/signout', async (req, reply) => {
|
fastify.get(
|
||||||
const logger = fastify.log.child({ req, res: reply });
|
'/signout',
|
||||||
|
{
|
||||||
|
schema: signout
|
||||||
|
},
|
||||||
|
async (req, reply) => {
|
||||||
|
const logger = fastify.log.child({ req, res: reply });
|
||||||
|
|
||||||
void reply.clearOurCookies();
|
void reply.clearOurCookies();
|
||||||
logger.info('User signed out');
|
logger.info('User signed out');
|
||||||
const { returnTo } = getRedirectParams(req);
|
|
||||||
await reply.redirect(returnTo);
|
await reply.send({});
|
||||||
});
|
}
|
||||||
|
);
|
||||||
done();
|
done();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -49,3 +49,4 @@ export {
|
|||||||
getUserExamEnvironmentToken
|
getUserExamEnvironmentToken
|
||||||
} from './schemas/user/exam-environment-token.js';
|
} from './schemas/user/exam-environment-token.js';
|
||||||
export { sentryPostEvent } from './schemas/sentry/event.js';
|
export { sentryPostEvent } from './schemas/sentry/event.js';
|
||||||
|
export { signout } from './schemas/signout/signout.js';
|
||||||
|
|||||||
9
api/src/schemas/signout/signout.ts
Normal file
9
api/src/schemas/signout/signout.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { Type } from '@fastify/type-provider-typebox';
|
||||||
|
import { genericError } from '../types.js';
|
||||||
|
|
||||||
|
export const signout = {
|
||||||
|
response: {
|
||||||
|
200: Type.Object({}),
|
||||||
|
default: genericError
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user