diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index e1672b7..fd4b5d6 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -7,6 +7,22 @@ on: - main jobs: + extract_environment: + runs-on: ubuntu-latest + outputs: + environment: ${{ steps.extract_environment.outputs.environment }} + steps: + - name: Extract Environment + run: | + if [ ${GITHUB_REF} == "refs/heads/main" ]; then + echo "##[set-output name=environment;]$(echo "prd")" + elif [ ${GITHUB_REF} == "refs/heads/alpha" ]; then + echo "##[set-output name=environment;]$(echo "dev")" + elif [ ${GITHUB_REF} == "refs/heads/beta" ]; then + echo "##[set-output name=environment;]$(echo "stg")" + fi + id: extract_environment + deploy: runs-on: self-hosted steps: diff --git a/src/middlewares/authentication.ts b/src/middlewares/authentication.ts index 8fb0ccb..3a7a1f9 100644 --- a/src/middlewares/authentication.ts +++ b/src/middlewares/authentication.ts @@ -95,29 +95,31 @@ const verifyToken = async (accessToken: string) => { try { await setUp(awsRegion, awsPoolId); - if (accessToken) { - const user: any = decode(accessToken, { complete: true }); - - if (user === null) { - throw new UnauthorizedException(); - } - - const { kid } = user.header; - const pem = pems.filter((item: any) => item[kid]); - const pemValue: any = pem[0][kid]; - - if (!pem) { - throw new UnauthorizedException(); - } - - verify(accessToken, pemValue, (err: any) => { - if (err) { - throw new UnauthorizedException(); - } - - return; - }); + if (!accessToken) { + throw new UnauthorizedException(); } + + const user: any = decode(accessToken, { complete: true }); + + if (user === null) { + throw new UnauthorizedException(); + } + + const { kid } = user.header; + const pem = pems.filter((item: any) => item[kid]); + const pemValue: any = pem[0][kid]; + + if (!pem) { + throw new UnauthorizedException(); + } + + verify(accessToken, pemValue, (err: any) => { + if (err) { + throw new UnauthorizedException(); + } + + return; + }); } catch (error) { throw new UnauthorizedException(); }