Skip to content

Commit

Permalink
added update color palette
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexi-Reyes committed Mar 3, 2024
1 parent d5fea95 commit 873db32
Show file tree
Hide file tree
Showing 21 changed files with 4,013 additions and 3,926 deletions.
40 changes: 20 additions & 20 deletions backend/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{
"env": {
"es2021": true,
"node": true
},
"ignorePatterns": ["node_modules", "dist", "data"],
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["@typescript-eslint"],
"rules": {
"indent": ["error", 4],
"linebreak-style": ["error", "unix"],
"quotes": ["error", "double"],
"semi": ["error", "always"],
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": ["warn"]
}
"env": {
"es2021": true,
"node": true
},
"ignorePatterns": ["node_modules", "dist", "data"],
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["@typescript-eslint"],
"rules": {
"indent": ["error", 4],
"linebreak-style": ["error", "unix"],
"quotes": ["error", "double"],
"semi": ["error", "always"],
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": ["warn"]
}
}
4 changes: 2 additions & 2 deletions backend/@types/french-badwords-list.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare module "french-badwords-list" {
const array: string[];
export { array };
const array: string[];
export { array };
}
8 changes: 4 additions & 4 deletions backend/@types/req.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
declare namespace Express {
export interface Request {
account: Account;
}
}
export interface Request {
account: Account;
}
}
67 changes: 42 additions & 25 deletions backend/auth/tokenUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import * as jwt from "jsonwebtoken";
* @returns The generated JWT token
*/
const generateJwtToken = (data: Token, exp: number): string => {
const secret: string = process.env.JWT_SECRET ?? "";
const token = jwt.sign(data, secret, { expiresIn: exp });
return token;
const secret: string = process.env.JWT_SECRET ?? "";

Check failure on line 12 in backend/auth/tokenUtils.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 4 spaces but found 2
const token = jwt.sign(data, secret, { expiresIn: exp });

Check failure on line 13 in backend/auth/tokenUtils.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 4 spaces but found 2
return token;

Check failure on line 14 in backend/auth/tokenUtils.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 4 spaces but found 2
};

/**
Expand All @@ -22,16 +22,16 @@ const generateJwtToken = (data: Token, exp: number): string => {
* @returns The decoded token
*/
const verifyJwtToken = (token: string, targetEmail: string): Token | null => {
try {
const secret: string = process.env.JWT_SECRET ?? "";
const decodedToken = jwt.verify(token, secret) as jwt.JwtPayload;
if (decodedToken.devinciEmail === targetEmail) {
return decodedToken as Token;
}
return null;
} catch (error) {
return null;
try {

Check failure on line 25 in backend/auth/tokenUtils.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 4 spaces but found 2
const secret: string = process.env.JWT_SECRET ?? "";

Check failure on line 26 in backend/auth/tokenUtils.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 8 spaces but found 4
const decodedToken = jwt.verify(token, secret) as jwt.JwtPayload;

Check failure on line 27 in backend/auth/tokenUtils.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 8 spaces but found 4
if (decodedToken.devinciEmail === targetEmail) {

Check failure on line 28 in backend/auth/tokenUtils.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 8 spaces but found 4
return decodedToken as Token;

Check failure on line 29 in backend/auth/tokenUtils.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 12 spaces but found 6
}

Check failure on line 30 in backend/auth/tokenUtils.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 8 spaces but found 4
return null;

Check failure on line 31 in backend/auth/tokenUtils.ts

View workflow job for this annotation

GitHub Actions / lint

Expected indentation of 8 spaces but found 4
} catch (error) {
return null;
}
};

/**
Expand All @@ -41,8 +41,11 @@ const verifyJwtToken = (token: string, targetEmail: string): Token | null => {
* @returns The generated authorization token
*/
const generateAuthorizationToken = (devinciEmail: string): string => {
const authorizationExpiration = 60 * 15; // 15 minutes
return generateJwtToken({ devinciEmail, type: "authorization" }, authorizationExpiration);
const authorizationExpiration = 60 * 15; // 15 minutes
return generateJwtToken(
{ devinciEmail, type: "authorization" },
authorizationExpiration,
);
};

/**
Expand All @@ -52,8 +55,11 @@ const generateAuthorizationToken = (devinciEmail: string): string => {
* @returns The generated authentication token
*/
const generateAuthenticationToken = (devinciEmail: string): string => {
const authenticationExpiration = 60 * 60 * 24 * 14; // 14 days
return generateJwtToken({ devinciEmail, type: "authentication" }, authenticationExpiration);
const authenticationExpiration = 60 * 60 * 24 * 14; // 14 days
return generateJwtToken(
{ devinciEmail, type: "authentication" },
authenticationExpiration,
);
};

/**
Expand All @@ -63,10 +69,13 @@ const generateAuthenticationToken = (devinciEmail: string): string => {
* @param targetEmail The email to be verified
* @returns Whether the token is valid
*/
const verifyAuthorizationToken = (token: string, targetEmail: string): boolean => {
const decodedToken = verifyJwtToken(token, targetEmail);
if (decodedToken === null) return false;
return decodedToken.type === "authorization";
const verifyAuthorizationToken = (
token: string,
targetEmail: string,
): boolean => {
const decodedToken = verifyJwtToken(token, targetEmail);
if (decodedToken === null) return false;
return decodedToken.type === "authorization";
};

/**
Expand All @@ -76,10 +85,18 @@ const verifyAuthorizationToken = (token: string, targetEmail: string): boolean =
* @param targetEmail The email to be verified
* @returns Whether the token is valid
*/
const verifyAuthenticationToken = (token: string, targetEmail: string): boolean => {
const decodedToken = verifyJwtToken(token, targetEmail);
if (decodedToken === null) return false;
return decodedToken.type === "authentication";
const verifyAuthenticationToken = (
token: string,
targetEmail: string,
): boolean => {
const decodedToken = verifyJwtToken(token, targetEmail);
if (decodedToken === null) return false;
return decodedToken.type === "authentication";
};

export { generateAuthorizationToken, generateAuthenticationToken, verifyAuthorizationToken, verifyAuthenticationToken };
export {
generateAuthorizationToken,
generateAuthenticationToken,
verifyAuthorizationToken,
verifyAuthenticationToken,
};
Loading

0 comments on commit 873db32

Please sign in to comment.