Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions modules/auth/controllers/auth.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,27 @@ const oauthCallback = async (req, res, next) => {
})(req, res, next);
};

/**
* @desc Endpoint to expose public auth sign-in/up feature flags
* @param {Object} req - Express request object
* @param {Object} res - Express response object
* @returns {void} Sends the public auth configuration (sign flags only) in the HTTP response
*/
const getConfig = (_req, res) => {
responses.success(res, 'Auth config')({
sign: {
in: !!config.sign.in,
up: !!config.sign.up,
},
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.
};

export default {
signup,
signin,
token,
oauthCall,
oauthCallback,
checkOAuthUserProfile,
getConfig,
};
3 changes: 3 additions & 0 deletions modules/auth/routes/auth.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import authPassword from '../controllers/auth.password.controller.js';
export default (app) => {
const authLimiter = rateLimit(config.rateLimit.auth);

// Public auth config (no authentication required, rate-limited)
app.route('/api/auth/config').get(authLimiter, auth.getConfig);
Comment thread
PierreBrisorgueil marked this conversation as resolved.

// Setting up the users password api
app.route('/api/auth/forgot').post(authLimiter, authPassword.forgot);
app.route('/api/auth/reset/:token').get(authLimiter, authPassword.validateResetToken);
Expand Down
28 changes: 28 additions & 0 deletions modules/auth/tests/auth.integration.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,34 @@ describe('Auth integration tests:', () => {
});
});

describe('Config endpoint', () => {
test('should return sign flags reflecting current config', async () => {
const result = await agent.get('/api/auth/config').expect(200);
expect(result.body.data).toEqual({
sign: {
in: expect.any(Boolean),
up: expect.any(Boolean),
},
});
});

test('should return false when sign.up is disabled', async () => {
const original = config.sign.up;
config.sign.up = false;
const result = await agent.get('/api/auth/config').expect(200);
expect(result.body.data.sign.up).toBe(false);
config.sign.up = original;
});

test('should return false when sign.in is disabled', async () => {
const original = config.sign.in;
config.sign.in = false;
const result = await agent.get('/api/auth/config').expect(200);
expect(result.body.data.sign.in).toBe(false);
config.sign.in = original;
});
});

// Mongoose disconnect
afterAll(async () => {
try {
Expand Down