Skip to content

Commit

Permalink
feat: Turn off waitlist feature using a feature flag.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lalit3716 committed Jul 14, 2024
1 parent 4765f0f commit 69654e2
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 49 deletions.
4 changes: 4 additions & 0 deletions api/src/config/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,7 @@ export const ASSET_FOLDER = process.env.ASSET_FOLDER || 'Vita';
export const ALLOW_MENTEE_SIGNUP = process.env.ALLOW_MENTEE_SIGNUP
? process.env.ALLOW_MENTEE_SIGNUP === 'true'
: false;

export const FEATURE_FLAGS = {
waitlist: process.env.WAITLIST_FEATURE || false,
};
19 changes: 16 additions & 3 deletions api/src/config/passport-config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import passport from 'passport';
import GoogleStrategy from 'passport-google-oauth20';
import LinkedinStrategy from 'passport-linkedin-oauth2';
import { CREATE_CALENDER_EMAIL, GOOGLE_KEY, LINKEDIN_KEY } from './keys';
import {
CREATE_CALENDER_EMAIL,
FEATURE_FLAGS,
GOOGLE_KEY,
LINKEDIN_KEY,
} from './keys';
import { UserModel } from '../Models/User';
import { Waitlist } from '../Models/Waitlist';
import { CalendarCredentialsModel } from '../Models/CalendarCredentials';
Expand Down Expand Up @@ -87,7 +92,11 @@ passport.use(
if (state.message === 'getRefreshToken') {
calendarEventCreationEmail(profile._json.email, _refreshToken, done);
} else {
if (state.loginMode === 'false' && state.isMentor === 'false') {
if (
state.loginMode === 'false' &&
state.isMentor === 'false' &&
FEATURE_FLAGS.waitlist
) {
const invite = await Waitlist.findOne({
inviteCode: state.inviteCode,
});
Expand Down Expand Up @@ -134,7 +143,11 @@ passport.use(
async (request, _accessToken, _refreshToken, profile, done) => {
const state = JSON.parse((request.query.state as string) || '{}');

if (state.loginMode === 'false' && state.isMentor === 'false') {
if (
state.loginMode === 'false' &&
state.isMentor === 'false' &&
FEATURE_FLAGS.waitlist
) {
const invite = await Waitlist.findOne({
inviteCode: state.inviteCode,
});
Expand Down
27 changes: 18 additions & 9 deletions api/src/controllers/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ASSET_FOLDER,
CLIENT_URL,
EMAIL_VERIFICATION_JWT,
FEATURE_FLAGS,
} from '../config/keys';
import { NextFunction, Request, Response } from 'express';
import { Document, Types } from 'mongoose';
Expand Down Expand Up @@ -195,20 +196,28 @@ const jwtSignup = async (req: Request, res: Response) => {
const { email, password, first_name, last_name, mentor, inviteCode } =
req.body;

if (!mentor) {
const invite = await Waitlist.findOne({ inviteCode });
if (FEATURE_FLAGS.waitlist) {
if (!mentor) {
const invite = await Waitlist.findOne({ inviteCode });

if (!invite || (invite.email !== email && invite.email !== '*')) {
return res.status(401).json({
error: 'Invalid or used invite code',
});
}
if (!invite || (invite.email !== email && invite.email !== '*')) {
return res.status(401).json({
error: 'Invalid or used invite code',
});
}

if (invite.email === email) {
await invite.remove();
if (invite.email === email) {
await invite.remove();
}
}
}

if (!/^[A-Za-z0-9._%+-][email protected]$/i.test(email)) {
return res.status(400).json({
error: 'You must use a Thapar email address',
});
}

const user = new UserModel({
email,
password,
Expand Down
3 changes: 2 additions & 1 deletion api/src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import notificationRoutes from './notification.routes';
import devRoutes from './dev.routes';
import waitlistRoutes from './waitlist.routes';
import topicRoutes from './topics.routes';
import { FEATURE_FLAGS } from '../config/keys';

const router = Router();

Expand All @@ -19,7 +20,7 @@ router.use(authRoutes);
router.use(bookingsRoutes);
router.use(webhooksRoutes);
router.use(notificationRoutes);
router.use(waitlistRoutes);
if (FEATURE_FLAGS.waitlist) router.use(waitlistRoutes);
router.use(devRoutes);
router.use(topicRoutes);

Expand Down
38 changes: 2 additions & 36 deletions client/src/components/AuthForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,13 @@ const AuthForm: React.FC = () => {

const role = watch('role');
const isMentor = role === 'mentor';
const inviteCode = watch('inviteCode');

const googleLogin = () => {
window.location.href = `${SERVER_URL}/api/auth/google?isMentor=${isMentor}&loginMode=${loginMode}&inviteCode=${inviteCode}`;
window.location.href = `${SERVER_URL}/api/auth/google?isMentor=${isMentor}&loginMode=${loginMode}`;
};

const linkedInLogin = () => {
window.location.href = `${SERVER_URL}/api/auth/linkedin?isMentor=${isMentor}&loginMode=${loginMode}&inviteCode=${inviteCode}`;
window.location.href = `${SERVER_URL}/api/auth/linkedin?isMentor=${isMentor}&loginMode=${loginMode}`;
};

useEffect(() => {
Expand Down Expand Up @@ -236,39 +235,6 @@ const AuthForm: React.FC = () => {
)}
/>
</Stack>
{role === 'mentee' && (
<Stack>
<Typography variant="body2">Invitation Code</Typography>
<Controller
control={control}
name="inviteCode"
defaultValue=""
rules={{
required: 'Invitation Code is required',
}}
render={({ field }) => (
<StyledTextField
{...field}
placeholder="Invitation Code"
error={Boolean(errors.inviteCode)}
helperText={
<Typography variant="body2" color="textSecondary">
Don&apos;t have an invitation code? Join the waitlist{' '}
<Link
sx={{
color: 'primary.main',
textDecoration: 'underline',
}}
to="/join-waitlist">
here
</Link>
</Typography>
}
/>
)}
/>
</Stack>
)}
<Stack direction="row" justifyContent="space-between" alignItems="center">
{!loginMode && (
<Stack spacing={1}>
Expand Down

0 comments on commit 69654e2

Please sign in to comment.