@ciscode/authentication-kit 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,48 +1,31 @@
1
- Auth Service (Express · JWT · Multi‑Tenant · RBAC)
2
- Internal package private to the company.
3
- This package is not published on npmjs. Install it only from the company’s Azure Artifacts feed using a project or user-level .npmrc.
1
+ Auth Service (NestJS, JWT, Multi-tenant, RBAC)
2
+ Internal package - private to the company.
3
+ This package is not published on npmjs. Install it only from the company Azure Artifacts feed using a project or user-level .npmrc.
4
4
 
5
- Authentication & authorization service for Node/Express apps.
6
- Provides local email/password auth with lockout, JWT access tokens + refresh, tenant scoping, RBAC, and optional Microsoft Entra (Azure AD) OAuth.
5
+ Authentication and authorization module for NestJS apps.
6
+ Provides local email/password auth with lockout, JWT access tokens and refresh, tenant scoping, RBAC, and optional OAuth (Microsoft Entra, Google, Facebook).
7
7
 
8
8
  Features
9
9
  Local auth (email/password) with account lockout policy.
10
10
  JWT access tokens (Bearer) and refresh endpoint (cookie or body).
11
11
  Multi-tenant scope on requests.
12
- RBAC (roles permission strings).
13
- Microsoft Entra (Azure AD) OAuth (optional).
12
+ RBAC (roles -> permission strings).
13
+ Microsoft Entra (Azure AD), Google, Facebook OAuth (optional).
14
14
  MongoDB/Mongoose models.
15
+
15
16
  Routes are mounted under:
16
17
 
17
18
  /api/auth (auth, password reset)
18
19
  /api/users (user admin)
19
20
  /api/auth/roles and /api/auth/permissions (RBAC)
20
- Installation (Azure Artifacts only)
21
- 1) Configure .npmrc
22
- Do not commit real tokens. Prefer ~/.npmrc or generate .npmrc in CI using secrets.
23
-
24
- For developers (user-level ~/.npmrc):
25
-
26
- registry=https://registry.npmjs.org/
27
-
28
- # Route @ciscodeapps scope to the private feed
29
- @ciscodeapps:registry=https://pkgs.dev.azure.com/CISCODEAPPS/Templates/_packaging/testfeed/npm/registry/
21
+ /api/admin (admin actions)
30
22
 
31
- //pkgs.dev.azure.com/CISCODEAPPS/Templates/_packaging/testfeed/npm/registry/:_authToken=${AZURE_ARTIFACTS_PAT}
32
- always-auth=true
33
- Set the token as an environment variable before installing:
23
+ Installation
34
24
 
35
- export AZURE_ARTIFACTS_PAT="<your PAT with Packaging:Read>"
36
- You can also use the username/_password form:
25
+ 1) Install the package
26
+ npm i @ciscode/authentication-kit
37
27
 
38
- //pkgs.dev.azure.com/...:username=AzureDevOps
39
- //pkgs.dev.azure.com/...:_password=${BASE64_PAT}
40
- //pkgs.dev.azure.com/...:email=not-used@localhost
41
- where BASE64_PAT=$(printf %s "$AZURE_ARTIFACTS_PAT" | base64).
42
-
43
- 2) Install the package
44
- npm i @ciscodeapps/auth-service
45
- 3) Required environment variables (host app)
28
+ 2) Required environment variables (host app)
46
29
  Create a .env in the host project:
47
30
 
48
31
  # Server
@@ -64,61 +47,59 @@ MAX_FAILED_LOGIN_ATTEMPTS=5
64
47
  ACCOUNT_LOCK_TIME_MINUTES=15
65
48
 
66
49
  # (Optional) Microsoft Entra ID (Azure AD)
67
- MICROSOFT_TENANT=organizations
50
+ MICROSOFT_TENANT_ID=common
68
51
  MICROSOFT_CLIENT_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
69
52
  MICROSOFT_CLIENT_SECRET=your-secret
70
53
  MICROSOFT_CALLBACK_URL=${BASE_URL}/api/auth/microsoft/callback
71
- Use inside an existing Express app
72
- Your package exports an Express app that already parses JSON, connects to Mongo, and mounts its routes. Just mount it:
73
54
 
74
- // server.js (host app)
75
- require('dotenv').config();
76
- const express = require('express');
77
- const authApp = require('@ciscodeapps/auth-service');
55
+ Use inside an existing Nest app
56
+ The module connects to Mongo on init and mounts its controllers.
57
+
58
+ // app.module.ts (host app)
59
+ import { Module } from '@nestjs/common';
60
+ import { AuthKitModule } from '@ciscode/authentication-kit';
61
+
62
+ @Module({
63
+ imports: [AuthKitModule]
64
+ })
65
+ export class AppModule {}
78
66
 
79
- const app = express();
80
- app.use(authApp); // exposes /api/auth, /api/users, /api/auth/roles, /api/auth/permissions
67
+ If you need to run it standalone, build and start the package:
81
68
 
82
- app.get('/health', (_, res) => res.json({ ok: true }));
83
- app.listen(process.env.PORT || 3000, () =>
84
- console.log('Host app on', process.env.PORT || 3000)
85
- );
86
- Prefer mounting the service. If you need to run it standalone, you can also start this package directly (it calls connectDB() on import).
69
+ npm run build
70
+ npm start
87
71
 
88
- What’s included (routes & behavior)
72
+ What is included (routes and behavior)
89
73
  Auth
90
- POST /api/auth/register Create a user (email/password).
91
- POST /api/auth/login Local login. On success, returns accessToken and may set a refreshToken httpOnly cookie.
92
- POST /api/auth/verify-otp – If OTP/step-up is enabled, verifies the code and completes login.
93
- POST /api/auth/refresh-token New access token from a valid refresh token (cookie or body).
94
- POST /api/auth/request-password-reset Sends a reset token (e.g., by email).
95
- PATCH /api/auth/reset-password – Consumes the reset token and sets a new password.
96
- GET /api/auth/microsoft → GET /api/auth/microsoft/callback – Optional Microsoft Entra OAuth; issues first-party tokens.
74
+ POST /api/auth/login - Local login. On success, returns accessToken and may set a refreshToken httpOnly cookie.
75
+ POST /api/auth/refresh-token - New access token from a valid refresh token (cookie or body).
76
+ POST /api/auth/request-password-reset - Sends a reset token (e.g., by email).
77
+ POST /api/auth/reset-password - Consumes the reset token and sets a new password.
78
+ GET /api/auth/microsoft - GET /api/auth/microsoft/callback - Optional Microsoft Entra OAuth; issues first-party tokens.
97
79
  Users
98
- GET /api/users List users (tenant-scoped, paginated).
99
- POST /api/users Create a user (requires permission).
80
+ GET /api/users - List users (tenant-scoped, paginated).
81
+ POST /api/users - Create a user.
100
82
  Additional CRUD endpoints as exposed by controllers.
101
- Roles & Permissions
102
- GET/POST /api/auth/roles Manage roles (name, tenantId, permissions: string[]).
103
- GET /api/auth/permissions List permission strings and metadata.
83
+ Roles and Permissions
84
+ GET/POST /api/auth/roles - Manage roles (name, tenantId, permissions: string[]).
85
+ GET /api/auth/permissions - List permission strings and metadata.
86
+
104
87
  Protecting your own routes (host app)
105
- const authenticate = require('@ciscodeapps/auth-service/src/middleware/authenticate'); // JWT
106
- const { hasPermission } = require('@ciscodeapps/auth-service/src/middleware/rbac.middleware'); // RBAC
107
-
108
- app.get('/reports',
109
- authenticate,
110
- hasPermission('reports:read'),
111
- (req, res) => res.json({ ok: true })
112
- );
88
+ import { UseGuards } from '@nestjs/common';
89
+ import { AuthenticateGuard, hasPermission } from '@ciscode/authentication-kit';
90
+
91
+ @UseGuards(AuthenticateGuard, hasPermission('reports:read'))
92
+ @Get('reports')
93
+ getReports() {
94
+ return { ok: true };
95
+ }
96
+
113
97
  Tenant scope comes from the JWT payload (e.g., tenantId) and is used inside controllers/guards to filter queries.
114
98
 
115
99
  Quick start (smoke tests)
116
- Start your host app:
117
-
118
- node server.js
119
- Register & Login
100
+ Start your host app, then create a user and log in:
120
101
 
121
- curl -X POST http://localhost:3000/api/auth/register \
102
+ curl -X POST http://localhost:3000/api/users \
122
103
  -H 'Content-Type: application/json' \
123
104
  -d '{"email":"a@b.com","password":"Secret123!","tenantId":"t-001","name":"Alice"}'
124
105
 
@@ -126,17 +107,20 @@ curl -X POST http://localhost:3000/api/auth/login \
126
107
  -H 'Content-Type: application/json' \
127
108
  -d '{"email":"a@b.com","password":"Secret123!","tenantId":"t-001"}'
128
109
  # => { "accessToken": "...", "refreshToken": "..." }
110
+
129
111
  Call a protected route
130
112
 
131
113
  ACCESS=<paste_access_token_here>
132
114
  curl http://localhost:3000/api/users -H "Authorization: Bearer $ACCESS"
115
+
133
116
  Refresh token
134
117
 
135
118
  curl -X POST http://localhost:3000/api/auth/refresh-token \
136
119
  -H 'Content-Type: application/json' \
137
120
  -d '{"refreshToken":"<paste_refresh_token_here>"}'
138
121
  # => { "accessToken": "..." }
139
- Microsoft OAuth (optional) - Visit: http://localhost:3000/api/auth/microsoft → complete sign-in.
122
+
123
+ Microsoft OAuth (optional) - Visit: http://localhost:3000/api/auth/microsoft to complete sign-in.
140
124
  - Callback: ${BASE_URL}/api/auth/microsoft/callback returns tokens (and may set the refresh cookie).
141
125
 
142
126
  CI/CD (Azure Pipelines)
@@ -151,7 +135,7 @@ CI/CD (Azure Pipelines)
151
135
 
152
136
  Security notes
153
137
  Never commit real PATs. Use env vars or CI secrets.
154
- Run behind HTTPS. Rotate JWT & refresh secrets periodically.
138
+ Run behind HTTPS. Rotate JWT and refresh secrets periodically.
155
139
  Limit login attempts; log auth events for auditing.
156
140
  License
157
- Internal Company proprietary.
141
+ Internal - Company proprietary.
package/package.json CHANGED
@@ -1,45 +1,70 @@
1
1
  {
2
- "name": "@ciscode/authentication-kit",
3
- "publishConfig": {
4
- "access": "public"
5
- },
6
- "repository": {
7
- "type": "git",
8
- "url": "git+https://github.com/CISCODE-MA/authentication-kit.git"
9
- },
10
- "version": "1.1.0",
11
- "description": "A login library with local login, Microsoft Entra ID authentication, password reset, and roles/permissions for multi-tenant applications.",
12
- "main": "src/index.js",
13
- "scripts": {
14
- "start": "node src/index.js",
15
- "test": "echo \"No tests defined\" && exit 0",
16
- "release": "semantic-release"
17
- },
18
- "keywords": [
19
- "login",
20
- "authentication",
21
- "microsoft-oauth",
22
- "password-reset",
23
- "roles",
24
- "permissions",
25
- "multi-tenant"
26
- ],
27
- "author": "Ciscode",
28
- "license": "MIT",
29
- "dependencies": {
30
- "bcryptjs": "^2.4.3",
31
- "crypto": "^1.0.1",
32
- "dotenv": "^16.0.3",
33
- "express": "^4.18.2",
34
- "jsonwebtoken": "^9.0.0",
35
- "mongoose": "^7.0.0",
36
- "mongoose-paginate-v2": "^1.7.1",
37
- "nodemailer": "^6.9.1",
38
- "passport": "^0.6.0",
39
- "passport-azure-ad-oauth2": "^0.0.4",
40
- "passport-local": "^1.0.0"
41
- },
42
- "devDependencies": {
43
- "semantic-release": "^25.0.2"
44
- }
2
+ "name": "@ciscode/authentication-kit",
3
+ "publishConfig": {
4
+ "access": "public"
5
+ },
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/CISCODE-MA/AuthKit.git"
9
+ },
10
+ "version": "1.1.1",
11
+ "description": "A login library with local login, Microsoft Entra ID authentication, password reset, and roles/permissions for multi-tenant applications.",
12
+ "main": "dist/index.js",
13
+ "types": "dist/index.d.ts",
14
+ "files": [
15
+ "dist",
16
+ "README.md",
17
+ "LICENSE"
18
+ ],
19
+ "scripts": {
20
+ "build": "tsc -p tsconfig.json",
21
+ "start": "node dist/standalone.js",
22
+ "test": "echo \"No tests defined\" && exit 0",
23
+ "release": "semantic-release"
24
+ },
25
+ "keywords": [
26
+ "login",
27
+ "authentication",
28
+ "microsoft-oauth",
29
+ "password-reset",
30
+ "roles",
31
+ "permissions",
32
+ "multi-tenant"
33
+ ],
34
+ "author": "Ciscode",
35
+ "license": "MIT",
36
+ "dependencies": {
37
+ "@nestjs/common": "^10.4.0",
38
+ "@nestjs/core": "^10.4.0",
39
+ "@nestjs/platform-express": "^10.4.0",
40
+ "axios": "^1.7.7",
41
+ "bcryptjs": "^2.4.3",
42
+ "cookie-parser": "^1.4.6",
43
+ "dotenv": "^16.0.3",
44
+ "express": "^4.18.2",
45
+ "jsonwebtoken": "^9.0.0",
46
+ "jwks-rsa": "^3.1.0",
47
+ "mongoose": "^7.0.0",
48
+ "mongoose-paginate-v2": "^1.7.1",
49
+ "nodemailer": "^7.0.12",
50
+ "passport": "^0.6.0",
51
+ "passport-azure-ad-oauth2": "^0.0.4",
52
+ "passport-facebook": "^3.0.0",
53
+ "passport-google-oauth20": "^2.0.0",
54
+ "passport-local": "^1.0.0",
55
+ "reflect-metadata": "^0.2.2",
56
+ "rxjs": "^7.8.1"
57
+ },
58
+ "devDependencies": {
59
+ "@types/cookie-parser": "^1.4.6",
60
+ "@types/express": "^4.17.21",
61
+ "@types/jsonwebtoken": "^9.0.6",
62
+ "@types/node": "^20.12.12",
63
+ "@types/passport-facebook": "^3.0.4",
64
+ "@types/passport-google-oauth20": "^2.0.15",
65
+ "@types/passport-local": "^1.0.38",
66
+ "semantic-release": "^25.0.2",
67
+ "ts-node": "^10.9.2",
68
+ "typescript": "^5.6.2"
69
+ }
45
70
  }
@@ -1,36 +0,0 @@
1
- name: CI
2
-
3
- on:
4
- pull_request:
5
- branches: [master, develop]
6
- push:
7
- branches: [develop]
8
-
9
- permissions:
10
- contents: read
11
-
12
- jobs:
13
- ci:
14
- runs-on: ubuntu-latest
15
- steps:
16
- - name: Checkout
17
- uses: actions/checkout@v4
18
-
19
- - name: Use Node.js
20
- uses: actions/setup-node@v4
21
- with:
22
- node-version: 22
23
- cache: npm
24
- registry-url: https://registry.npmjs.org/
25
-
26
- - name: Install dependencies
27
- run: npm ci
28
-
29
- - name: Lint
30
- run: npm run lint --if-present
31
-
32
- - name: Test
33
- run: npm test --if-present
34
-
35
- - name: Build
36
- run: npm run build --if-present
@@ -1,30 +0,0 @@
1
- name: Publish to npm
2
-
3
- on:
4
- push:
5
- tags:
6
- - "v*.*.*"
7
-
8
- permissions:
9
- contents: read
10
- id-token: write
11
-
12
- jobs:
13
- publish:
14
- runs-on: ubuntu-latest
15
- steps:
16
- - uses: actions/checkout@v4
17
-
18
- - uses: actions/setup-node@v4
19
- with:
20
- node-version: 22
21
- registry-url: https://registry.npmjs.org/
22
- cache: npm
23
- - name: Install dependencies
24
- run: npm ci
25
- - name: Build library
26
- run: npm run build:lib --if-present
27
- - name: Publish to npm
28
- run: npm publish --access public --provenance
29
- env:
30
- NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
package/CODE_OF_CONDUCT DELETED
@@ -1,38 +0,0 @@
1
- # Code of Conduct
2
-
3
- This project adheres to the Contributor Covenant Code of Conduct.
4
-
5
- ---
6
-
7
- ## Our Pledge
8
-
9
- We pledge to make participation in this project a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity.
10
-
11
- ---
12
-
13
- ## Our Standards
14
-
15
- Examples of behavior that contributes to a positive environment include:
16
- - Being respectful and inclusive
17
- - Giving and accepting constructive feedback
18
- - Focusing on what is best for the community
19
-
20
- Examples of unacceptable behavior include:
21
- - Harassment or discriminatory language
22
- - Personal attacks or trolling
23
- - Publishing private information without consent
24
-
25
- ---
26
-
27
- ## Enforcement
28
-
29
- Project maintainers are responsible for clarifying and enforcing standards of acceptable behavior.
30
-
31
- Instances of abusive behavior may be reported to the maintainers through private communication channels.
32
-
33
- ---
34
-
35
- ## Attribution
36
-
37
- This Code of Conduct is adapted from the Contributor Covenant
38
- version 2.1 — https://www.contributor-covenant.org/
package/CONTRIBUTING.md DELETED
@@ -1,40 +0,0 @@
1
- # Contributing
2
-
3
- Thank you for your interest in contributing to this project.
4
-
5
- Contributions of all kinds are welcome, including bug reports, feature requests, documentation improvements, and code contributions.
6
-
7
- ---
8
-
9
- ## How to Contribute
10
-
11
- 1. Fork the repository
12
- 2. Create a new branch from `main`
13
- 3. Make your changes
14
- 4. Add or update tests where applicable
15
- 5. Ensure existing tests pass
16
- 6. Open a pull request with a clear description
17
-
18
- ---
19
-
20
- ## Guidelines
21
-
22
- - Keep changes focused and minimal
23
- - Follow existing code style and conventions
24
- - Avoid breaking backward compatibility when possible
25
- - Write clear commit messages
26
- - Do not include secrets, credentials, or tokens
27
-
28
- ---
29
-
30
- ## Reporting Bugs
31
-
32
- When reporting bugs, please include:
33
- - A clear description of the issue
34
- - Steps to reproduce
35
- - Expected vs actual behavior
36
- - Relevant logs or error messages (redacted if needed)
37
-
38
- ---
39
-
40
- By contributing, you agree that your contributions will be licensed under the same license as the project.
package/SECURITY DELETED
@@ -1,31 +0,0 @@
1
- # Security Policy
2
-
3
- Security is taken seriously in this project.
4
-
5
- If you discover a security vulnerability, please **do not open a public issue**.
6
-
7
- ---
8
-
9
- ## Reporting a Vulnerability
10
-
11
- Please report security issues privately by contacting the maintainers using one of the following methods:
12
-
13
- - Email the address listed in the repository’s contact or maintainer information
14
- - Use private disclosure channels if available on the hosting platform
15
-
16
- When reporting, please include:
17
- - A description of the vulnerability
18
- - Steps to reproduce
19
- - Potential impact
20
- - Any suggested mitigations (if known)
21
-
22
- ---
23
-
24
- ## Security Best Practices
25
-
26
- - Never commit secrets or credentials
27
- - Use strong, rotated secrets for JWT signing
28
- - Run services behind HTTPS
29
- - Apply rate limiting and monitoring in production environments
30
-
31
- We appreciate responsible disclosure and will work to address issues promptly.
@@ -1,100 +0,0 @@
1
- trigger:
2
- - main
3
-
4
- pool:
5
- vmImage: 'ubuntu-latest'
6
-
7
- variables:
8
- - group: BE # AZURE_ARTIFACTS_PAT lives here; add NPM_TOKEN and (optionally) GH_PAT as secrets
9
-
10
- # Optional toggles (default = behave exactly like your old pipeline: publish only to Azure Artifacts)
11
- parameters:
12
- - name: pushToGitHub
13
- type: boolean
14
- default: false
15
- - name: publishToNpm
16
- type: boolean
17
- default: false
18
- - name: packagePath
19
- type: string
20
- default: 'modules/login'
21
-
22
- steps:
23
- # Allows pushing back to GitHub if pushToGitHub=true (we'll still use GH_PAT if provided)
24
- - checkout: self
25
- persistCredentials: true
26
- displayName: 'Checkout (allows push when enabled)'
27
-
28
- # 1) Use Node.js (unchanged)
29
- - task: NodeTool@0
30
- inputs:
31
- versionSpec: '20.x'
32
- displayName: 'Use Node.js'
33
-
34
- # 2) Authenticate with Azure Artifacts (unchanged)
35
- - script: |
36
- echo "Setting up npm authentication for Azure Artifacts..."
37
- echo "//pkgs.dev.azure.com/CISCODEAPPS/Templates/_packaging/testfeed/npm/registry/:_authToken=$(AZURE_ARTIFACTS_PAT)" > ~/.npmrc
38
- npm set registry "https://pkgs.dev.azure.com/CISCODEAPPS/Templates/_packaging/testfeed/npm/registry/"
39
- displayName: 'Authenticate with Azure Artifacts'
40
-
41
- # 3) Bump + publish to Azure Artifacts (mandatory)
42
- - script: |
43
- set -e
44
- echo "Bumping package version before publishing login..."
45
- cd ${{ parameters.packagePath }}
46
- npm version patch --no-git-tag-version
47
-
48
- # capture for optional steps
49
- NEW_VERSION=$(node -p "require('./package.json').version")
50
- PKG_NAME=$(node -p "require('./package.json').name")
51
- echo "Decided version: ${NEW_VERSION} for ${PKG_NAME}"
52
- echo "##vso[task.setvariable variable=NEW_VERSION]$NEW_VERSION"
53
- echo "##vso[task.setvariable variable=PKG_NAME]$PKG_NAME"
54
-
55
- # sanity: see what will be published
56
- npm pack --dry-run
57
-
58
- # publish to Azure Artifacts (mandatory)
59
- npm publish --registry=https://pkgs.dev.azure.com/CISCODEAPPS/Templates/_packaging/testfeed/npm/registry/
60
- displayName: 'Publish authentication module (Azure Artifacts - mandatory)'
61
-
62
- # OPTIONAL: push the version bump back to GitHub
63
- - ${{ if eq(parameters.pushToGitHub, true) }}:
64
- - script: |
65
- set -e
66
- cd ${{ parameters.packagePath }}
67
-
68
- # bot identity for the commit
69
- git config user.name "azure-pipelines[bot]"
70
- git config user.email "azure-pipelines-bot@example.local"
71
-
72
- # If a GitHub PAT is provided, use it to ensure push works (esp. with GitHub App connections)
73
- if [ -n "$(GH_PAT)" ]; then
74
- echo "Using GH_PAT to authenticate push..."
75
- git remote set-url origin "https://x-access-token:$(GH_PAT)@github.com/CISCODE-MA/auth_package"
76
- fi
77
-
78
- git add package.json package-lock.json || true
79
- git commit -m "chore(login): bump $(PKG_NAME) to v$(NEW_VERSION) [skip ci]" || echo "No changes to commit"
80
- git push origin HEAD:$(Build.SourceBranchName)
81
- displayName: 'Push version bump to GitHub (optional)'
82
-
83
- # OPTIONAL: publish same version to npm public (with pre-check)
84
- - ${{ if eq(parameters.publishToNpm, true) }}:
85
- - script: |
86
- set -e
87
- echo "Switching npm auth to npm public..."
88
- rm -f ~/.npmrc || true
89
- echo "//registry.npmjs.org/:_authToken=$(NPM_TOKEN)" > ~/.npmrc
90
- npm set registry "https://registry.npmjs.org/"
91
-
92
- cd ${{ parameters.packagePath }}
93
-
94
- # Skip if the exact version already exists on npm
95
- if npm view "$(PKG_NAME)@$(NEW_VERSION)" version >/dev/null 2>&1; then
96
- echo "$(PKG_NAME)@$(NEW_VERSION) already exists on npm; skipping publish."
97
- else
98
- npm publish --access public
99
- fi
100
- displayName: 'Publish to npm public (optional)'
@@ -1,21 +0,0 @@
1
- const mongoose = require('mongoose');
2
- require('dotenv').config();
3
-
4
- // Optionally, set strictQuery per Mongoose recommendations
5
- mongoose.set('strictQuery', false);
6
-
7
- const connectDB = async () => {
8
- try {
9
- const mongoURI = process.env.MONGO_URI_T;
10
- if (!mongoURI) {
11
- throw new Error('MONGO_URI is not defined in the environment variables.');
12
- }
13
- await mongoose.connect(mongoURI);
14
- console.log("MongoDB Connected...");
15
- } catch (error) {
16
- console.error("MongoDB Connection Error:", error);
17
- process.exit(1);
18
- }
19
- };
20
-
21
- module.exports = connectDB;