ShiftWise API Docs
    Preparing search index...

    Function requireAuth

    • Authentication middleware — Layer 1 of 2.

      Extracts the Bearer token from the Authorization header, verifies it, and fetches the corresponding user from the database. Attaches the full User record to req.user for downstream handlers.

      Calls next(Unauthorized(...)) if:

      • The Authorization header is missing or malformed
      • The token is expired or has an invalid signature
      • The user no longer exists in the database

      Parameters

      Returns Promise<void>

      router.get('/profile', requireAuth, (req: AuthRequest, res) => {
      Ok(res, { name: req.user!.name })
      })