mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2025-12-19 10:07:46 -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 { devLogin, setupServer, superRequest } from '../../../vitest.utils.js';
|
||||
import { HOME_LOCATION } from '../../utils/env.js';
|
||||
|
||||
describe('GET /signout', () => {
|
||||
setupServer();
|
||||
@@ -29,12 +28,9 @@ describe('GET /signout', () => {
|
||||
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' });
|
||||
|
||||
// TODO: separate the validation and normalization logic.
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
expect(res.headers.location).toBe(`${HOME_LOCATION}/`);
|
||||
expect(res.status).toBe(302);
|
||||
expect(res.body).toEqual({});
|
||||
expect(res.status).toBe(200);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { FastifyPluginCallback } from 'fastify';
|
||||
|
||||
import { getRedirectParams } from '../../utils/redirection.js';
|
||||
import { signout } from '../../schemas.js';
|
||||
|
||||
/**
|
||||
* Route handler for signing out.
|
||||
@@ -15,13 +15,19 @@ export const signoutRoute: FastifyPluginCallback = (
|
||||
_options,
|
||||
done
|
||||
) => {
|
||||
fastify.get('/signout', async (req, reply) => {
|
||||
const logger = fastify.log.child({ req, res: reply });
|
||||
fastify.get(
|
||||
'/signout',
|
||||
{
|
||||
schema: signout
|
||||
},
|
||||
async (req, reply) => {
|
||||
const logger = fastify.log.child({ req, res: reply });
|
||||
|
||||
void reply.clearOurCookies();
|
||||
logger.info('User signed out');
|
||||
const { returnTo } = getRedirectParams(req);
|
||||
await reply.redirect(returnTo);
|
||||
});
|
||||
void reply.clearOurCookies();
|
||||
logger.info('User signed out');
|
||||
|
||||
await reply.send({});
|
||||
}
|
||||
);
|
||||
done();
|
||||
};
|
||||
|
||||
@@ -49,3 +49,4 @@ export {
|
||||
getUserExamEnvironmentToken
|
||||
} from './schemas/user/exam-environment-token.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