Skip to content

Commit

Permalink
Delay licence check & fix return code on bad passwords (#309)
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinejaussoin authored Oct 2, 2021
1 parent 1ad03d3 commit 01060dd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
20 changes: 18 additions & 2 deletions backend/src/auth/router.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import express, { Request, Response } from 'express';
import express, { NextFunction, Request, Response } from 'express';
import passport from 'passport';

const router = express.Router();
Expand All @@ -12,7 +12,23 @@ const githubAuth = passport.authenticate('github', { scope: ['user:email'] });
const slackAuth = passport.authenticate('slack');
const microsoftAuth = passport.authenticate('microsoft');
const oktaAuth = passport.authenticate('okta');
const anonAuth = passport.authenticate('local');

function anonAuth(req: Request, res: Response, next: NextFunction) {
passport.authenticate('local', function (err, user) {
if (err) {
return res.status(403).send().end();
}
if (!user) {
return res.status(403).send().end();
}
req.logIn(user, function (err) {
if (err) {
return next(err);
}
return res.status(200).send().end();
});
})(req, res, next);
}

export const endOAuthHandler = (req: Request, res: Response) => {
const io = req.app.get('io');
Expand Down
2 changes: 2 additions & 0 deletions backend/src/security/is-licenced.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { SelfHostedCheckPayload } from '@retrospected/common';
import config from '../config';
import fetch from 'node-fetch';
import wait from '../utils';

let licenced: boolean | null = null;

Expand All @@ -12,6 +13,7 @@ export async function isLicenced() {
if (licenced !== null) {
return licenced;
}
await wait(3000);
const result = await isLicencedBase();
licenced = result;
return result;
Expand Down

0 comments on commit 01060dd

Please sign in to comment.