Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

Fix merge conflicts

Tuan Dang30b2b8544697
diff --cc backend/src/controllers/v1/signupController.ts
index 961bb162cd,dad9632db9..1c5c9e2980
--- a/backend/src/controllers/v1/signupController.ts
+++ b/backend/src/controllers/v1/signupController.ts
@@@ -1,12 -1,17 +1,13 @@@
import { Request, Response } from 'express';
import * as Sentry from '@sentry/node';
- import { JWT_SIGNUP_LIFETIME, JWT_SIGNUP_SECRET } from '../../config';
-import { NODE_ENV, JWT_SIGNUP_LIFETIME, JWT_SIGNUP_SECRET, INVITE_ONLY_SIGNUP } from '../../config';
-import { User, MembershipOrg } from '../../models';
-import { completeAccount } from '../../helpers/user';
+import { User } from '../../models';
++import { JWT_SIGNUP_LIFETIME, JWT_SIGNUP_SECRET, INVITE_ONLY_SIGNUP } from '../../config';
import {
sendEmailVerification,
checkEmailVerification,
- initializeDefaultOrg
} from '../../helpers/signup';
-import { issueTokens, createToken } from '../../helpers/auth';
-import { INVITED, ACCEPTED } from '../../variables';
-import axios from 'axios';
+import { createToken } from '../../helpers/auth';
+ import { BadRequestError } from '../../utils/errors';
/**
* Signup step 1: Initialize account for user under email [email] and send a verification code
@@@ -98,4 -111,202 +107,4 @@@ export const verifyEmailSignup = async
user,
token
});
- };
+ };
-
-/**
- * Complete setting up user by adding their personal and auth information as part of the
- * signup flow
- * @param req
- * @param res
- * @returns
- */
-export const completeAccountSignup = async (req: Request, res: Response) => {
- let user, token, refreshToken;
- try {
- const {
- email,
- firstName,
- lastName,
- publicKey,
- encryptedPrivateKey,
- iv,
- tag,
- salt,
- verifier,
- organizationName
- } = req.body;
-
- // get user
- user = await User.findOne({ email });
-
- if (!user || (user && user?.publicKey)) {
- // case 1: user doesn't exist.
- // case 2: user has already completed account
- return res.status(403).send({
- error: 'Failed to complete account for complete user'
- });
- }
-
- // complete setting up user's account
- user = await completeAccount({
- userId: user._id.toString(),
- firstName,
- lastName,
- publicKey,
- encryptedPrivateKey,
- iv,
- tag,
- salt,
- verifier
- });
-
- if (!user)
- throw new Error('Failed to complete account for non-existent user'); // ensure user is non-null
-
- // initialize default organization and workspace
- await initializeDefaultOrg({
- organizationName,
- user
- });
-
- // update organization membership statuses that are
- // invited to completed with user attached
- await MembershipOrg.updateMany(
- {
- inviteEmail: email,
- status: INVITED
- },
- {
- user,
- status: ACCEPTED
- }
- );
-
- // issue tokens
- const tokens = await issueTokens({
- userId: user._id.toString()
- });
-
- token = tokens.token;
- refreshToken = tokens.refreshToken;
-
- // sending a welcome email to new users
- if (process.env.LOOPS_API_KEY) {
- await axios.post("https://app.loops.so/api/v1/events/send", {
- "email": email,
- "eventName": "Sign Up",
- "firstName": firstName,
- "lastName": lastName
- }, {
- headers: {
- "Accept": "application/json",
- "Authorization": "Bearer " + process.env.LOOPS_API_KEY
- },
- });
- }
- } catch (err) {
- Sentry.setUser(null);
- Sentry.captureException(err);
- return res.status(400).send({
- message: 'Failed to complete account setup'
- });
- }
-
- return res.status(200).send({
- message: 'Successfully set up account',
- user,
- token,
- refreshToken
- });
-};
-/**
- * Complete setting up user by adding their personal and auth information as part of the
- * invite flow
- * @param req
- * @param res
- * @returns
- */
-export const completeAccountInvite = async (req: Request, res: Response) => {
- let user, token, refreshToken;
- try {
- const {
- email,
- firstName,
- lastName,
- publicKey,
- encryptedPrivateKey,
- iv,
- tag,
- salt,
- verifier
- } = req.body;
-
- // get user
- user = await User.findOne({ email });
-
- if (!user || (user && user?.publicKey)) {
- // case 1: user doesn't exist.
- // case 2: user has already completed account
- return res.status(403).send({
- error: 'Failed to complete account for complete user'
- });
- }
-
- const membershipOrg = await MembershipOrg.findOne({
- inviteEmail: email,
- status: INVITED
- });
-
- if (!membershipOrg) throw new Error('Failed to find invitations for email');
-
- // complete setting up user's account
- user = await completeAccount({
- userId: user._id.toString(),
- firstName,
- lastName,
- publicKey,
- encryptedPrivateKey,
- iv,
- tag,
- salt,
- verifier
- });
-
- if (!user)
- throw new Error('Failed to complete account for non-existent user');
-
- // update organization membership statuses that are
- // invited to completed with user attached
- await MembershipOrg.updateMany(
- {
- inviteEmail: email,
- status: INVITED
- },
- {
- user,
- status: ACCEPTED
- }
- );
-
- // issue tokens
- const tokens = await issueTokens({
- userId: user._id.toString()
- });
-
- token = tokens.token;
- refreshToken = tokens.refreshToken;
- } catch (err) {
- Sentry.setUser(null);
- Sentry.captureException(err);
- return res.status(400).send({
- message: 'Failed to complete account setup'
- });
- }
-
- return res.status(200).send({
- message: 'Successfully set up account',
- user,
- token,
- refreshToken
- });
-};
diff --cc backend/src/models/token.ts
index 0000000000,2da62d8138..c003e42a27
mode 000000,100644..100644
--- a/backend/src/models/token.ts
+++ b/backend/src/models/token.ts
@@@ -1,0 -1,33 +1,33 @@@
+ import { Schema, model } from 'mongoose';
+ import { EMAIL_TOKEN_LIFETIME } from '../config';
+
+ export interface IToken {
+ email: string;
+ token: string;
+ createdAt: Date;
- ttl: Number;
++ ttl: number;
+ }
+
+ const tokenSchema = new Schema<IToken>({
+ email: {
+ type: String,
+ required: true
+ },
+ token: {
+ type: String,
+ required: true
+ },
+ createdAt: {
+ type: Date,
+ default: Date.now
+ },
+ ttl: {
+ type: Number,
+ }
+ });
+
+ tokenSchema.index({ email: 1 });
+
+ const Token = model<IToken>('Token', tokenSchema);
+
+ export default Token;