Skip to content

Commit ba775e7

Browse files
Fix/missing secret env (#402)
* Added missing secret in env * test: deployment * feat: run the action on push --------- Co-authored-by: ceelogre <[email protected]>
1 parent d68b43b commit ba775e7

14 files changed

+28
-27
lines changed

.github/workflows/deployments.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ on:
33
push:
44
branches:
55
- develop
6+
67
workflow_dispatch:
78

89
jobs:

src/context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Request } from 'express'
44
import * as jwt from 'jsonwebtoken'
55
import requestIp from 'request-ip'
66

7-
const SECRET = process.env.SECRET
7+
const SECRET = (process.env.SECRET as string) || 'mysq_unique_secret'
88

99
export interface AuthTokenPayload {
1010
userId: string

src/helpers/generateInvitationToken.helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import jwt from 'jsonwebtoken'
2-
const SECRET: string = process.env.SECRET as string
2+
const SECRET = (process.env.SECRET as string) || 'mysq_unique_secret'
33

44
export default async function generateInvitationTokenAndLink(
55
email: string,

src/helpers/organization.helper.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { JwtPayload, verify } from 'jsonwebtoken'
44
import { Organization } from '../models/organization.model'
55

66
export async function checkLoggedInOrganization(token?: string) {
7-
const SECRET = process.env.SECRET as string
7+
const SECRET = (process.env.SECRET as string) || 'mysq_unique_secret'
88

99
if (!token) {
1010
throw new GraphQLError('Not logged in an organization', {

src/helpers/sendEventEmails.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export async function sendEventInvitations(
1818
eventTimeToEnd: string
1919
) {
2020
try {
21-
const secret = process.env.SECRET!
21+
const secret = (process.env.SECRET as string) || 'mysq_unique_secret'
2222
const acceptedEventToken = jwt.sign(
2323
{
2424
email,

src/helpers/sendInvitaitonEmail.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ interface Payload {
1111
orgToken: string
1212
}
1313

14-
const SECRET: string = process.env.SECRET as string
14+
const SECRET = (process.env.SECRET as string) || 'mysq_unique_secret'
1515
export default async function sendInvitationEmail(
1616
email: string,
1717
orgName: string,

src/helpers/user.helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { RoleOfUser, User } from '../models/user'
33
import { Context } from './../context'
44
import * as jwt from 'jsonwebtoken'
55

6-
const SECRET: string = process.env.SECRET as string
6+
const SECRET = (process.env.SECRET as string) || 'mysq_unique_secret'
77

88
export const generateToken = (userId: string, role: string) => {
99
return jwt.sign({ userId, role }, SECRET, { expiresIn: '2h' })

src/resolvers/cohort.resolvers.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -318,12 +318,16 @@ const resolvers = {
318318

319319
if (
320320
endDate &&
321-
(isAfter(new Date(startDate.toString()),
322-
new Date(endDate.toString())) ||
323-
isAfter(new Date(cohort?.startDate?.toString() || ''),
324-
new Date(endDate)))
321+
(isAfter(
322+
new Date(startDate.toString()),
323+
new Date(endDate.toString())
324+
) ||
325+
isAfter(
326+
new Date(cohort?.startDate?.toString() || ''),
327+
new Date(endDate)
328+
))
325329
) {
326-
throw new GraphQLError('End Date can\'t be before Start Date', {
330+
throw new GraphQLError("End Date can't be before Start Date", {
327331
extensions: {
328332
code: 'VALIDATION_ERROR',
329333
},
@@ -402,9 +406,8 @@ const resolvers = {
402406
cohort.name = name
403407
notificationChanges.push('Name')
404408
}
405-
if (phaseName && cohort.phase.toString() !== phase.id.toString()) {
406-
cohort.phase = phase.id;
407-
addNewAttendanceWeek();
409+
if (phaseName && cohort?.phase?.toString() !== phase?.id?.toString()) {
410+
cohort.phase = phase.id
408411
notificationChanges.push('Phase')
409412
}
410413

src/resolvers/coordinatorResolvers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import RemoveTraineeTemplate from '../utils/templates/removeTraineeTamplete'
1919
import { Context } from './../context'
2020
import { Document, ObjectId } from 'mongoose'
2121

22-
const SECRET: string = process.env.SECRET as string
22+
const SECRET = (process.env.SECRET as string) || 'mysq_unique_secret'
2323

2424
interface TraineeStatus {
2525
days: string

src/resolvers/eventResolver.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ const validateTime = (
6161

6262
const decodeEventResponseToken = (token: string) => {
6363
try {
64-
return jwt.verify(token, process.env.SECRET!) as EventResponse
64+
return jwt.verify(
65+
token,
66+
(process.env.SECRET as string) || 'mysq_unique_secret'
67+
) as EventResponse
6568
} catch (err: any) {
6669
throw new GraphQLError('Invalid Token', {
6770
extensions: {

0 commit comments

Comments
 (0)