LearnersGuild/idm-jwt-auth

View on GitHub

Showing 5 of 5 total issues

Function refreshUserFromIDMService has 50 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export async function refreshUserFromIDMService(req, res, next) {
  try {
    // if this middleware is being invoked from within this module, skip it
    // (see `idmGraphQLFetch` in `utils.js`)
    const skip = req.get('LearnersGuild-Skip-Update-User-Middleware')
Severity: Minor
Found in src/middlewares.js - About 2 hrs to fix

    Function refreshUserFromIDMService has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

    export async function refreshUserFromIDMService(req, res, next) {
      try {
        // if this middleware is being invoked from within this module, skip it
        // (see `idmGraphQLFetch` in `utils.js`)
        const skip = req.get('LearnersGuild-Skip-Update-User-Middleware')
    Severity: Minor
    Found in src/middlewares.js - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function extendJWTExpiration has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    export function extendJWTExpiration(req, res, next) {
      if (process.env.JWT_PRIVATE_KEY && req.user) {
        if (req.user.active) {
          try {
            const jwtClaims = jwtClaimsForUser(req.user)
    Severity: Minor
    Found in src/middlewares.js - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Function idmGraphQLFetch has 32 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export function idmGraphQLFetch(graphQLParams, token = null) {
      if (!process.env.IDM_BASE_URL) {
        throw new Error('IDM_BASE_URL must be set in environment')
      }
      const options = {
    Severity: Minor
    Found in src/utils.js - About 1 hr to fix

      Function addUserToRequestFromJWT has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

      export function addUserToRequestFromJWT(req, res, next) {
        if (!req.user || !req.lgJWT) {
          try {
            const lgJWT = getToken(req)
            if (lgJWT) {
      Severity: Minor
      Found in src/middlewares.js - About 1 hr to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Severity
      Category
      Status
      Source
      Language