diff --git a/api/src/routes/public/signout.test.ts b/api/src/routes/public/signout.test.ts index 5f8619d1982..42f583fb53b 100644 --- a/api/src/routes/public/signout.test.ts +++ b/api/src/routes/public/signout.test.ts @@ -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); }); }); diff --git a/api/src/routes/public/signout.ts b/api/src/routes/public/signout.ts index 183882e3661..90ac5044ede 100644 --- a/api/src/routes/public/signout.ts +++ b/api/src/routes/public/signout.ts @@ -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(); }; diff --git a/api/src/schemas.ts b/api/src/schemas.ts index 08bcb8bf5df..f895abba3ee 100644 --- a/api/src/schemas.ts +++ b/api/src/schemas.ts @@ -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'; diff --git a/api/src/schemas/signout/signout.ts b/api/src/schemas/signout/signout.ts new file mode 100644 index 00000000000..a112dcd4c38 --- /dev/null +++ b/api/src/schemas/signout/signout.ts @@ -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 + } +};