A lightweight NestJS GraphQL backend for ConnectyCube apps. This GraphQL API provides secure user registration, authentication and real-time chat backed by MongoDB and ConnectyCube, making it easy to build chat apps, messaging apps, and RTC applications with a ConnectyCube server-side auth flow.
- Register users into MongoDB via Mongoose
- Create a corresponding ConnectyCube user account
- Authenticate users using email/password
- Issue JWT access tokens (via
@nestjs/jwt) - Create ConnectyCube sessions (standard and system-token-based)
src/modules/auth/- Authentication logicauth.service.ts- user CRUD, JWT generation, ConnectyCube integrationauth.resolver.ts- GraphQL mutations (register,login)connectyCube.service.ts- wrapper around ConnectyCube SDK callsdtos/- GraphQL input/output typesmodel/- Mongoose schema for users
- Install dependencies:
npm install- Configure environment variables (e.g.,
.env):
MONGO_URI=mongodb://localhost:27017/connecty_cube_api
JWT_SECRET=your_jwt_secret
APP_ID=<connectycube_app_id>
AUTH_KEY=<connectycube_auth_key>- Start the server:
npm run start:devVisit the GraphQL Playground: http://localhost:3000/api
- When a user registers, the backend:
- Stores the user in MongoDB (hashed password)
- Creates a corresponding user in ConnectyCube using the same email + password
- Saves the ConnectyCube user ID on the user record
✅ This gives the user a ConnectyCube identity without requiring manual sync.
- The user provides email + password.
- Backend validates the password and issues a JWT.
- Backend also creates a ConnectyCube session using the same credentials.
⚠️ This flow requires the ConnectyCube user password to match your system password.
This flow lets your backend be the single source of truth for credentials and avoids the need to keep ConnectyCube passwords in sync:
- User logs in with email + password.
- Backend validates credentials and issues its own JWT (
token). - Backend requests a ConnectyCube session by providing the JWT as the
loginvalue and a fixed system password (e.g.cidp-temporary-password). - ConnectyCube calls your
/auth/verify-connectycubeendpoint with the JWT to verify it. - If the JWT is valid, your endpoint returns the user payload (including
external_id) and ConnectyCube issues a session.
✅ This avoids needing to update ConnectyCube passwords when users change theirs in your system.
mutation Register($body: UserRegisterInput!) {
register(body: $body) {
message
user {
id
email
firstName
lastName
}
}
}mutation Login($body: LoginUserDto!) {
login(body: $body) {
message
token
connectySession
}
}This flow avoids storing/updating passwords in ConnectyCube by using a system JWT as the ConnectyCube "password" when creating a session. It is useful when you want your backend to be the single source of truth for user credentials.
mutation LoginByToken($body: LoginUserDto!) {
login_By_token(body: $body) {
message
token
connectySession
ccUserId
}
}ConnectyCube can be configured to call your API for system-token verification.
- Endpoint:
GET /auth/verify-connectycube?token=<system_jwt> - Validates the JWT issued by this API and returns the user payload that ConnectyCube uses as
external_id.
Example response:
{
"user": {
"id": "<your-internal-user-id>",
"email": "user@example.com"
}
}npm run test
npm run test:e2enpm run build
npm run start:prodIf you'd like to extend the project (refresh tokens, role-based auth, REST endpoints, etc.), the auth module is a good starting point.