Complete guide to using our GraphQL Authentication API
Our API provides a comprehensive authentication system built on Apollo GraphQL and Express. It offers secure user management capabilities with JWT-based authentication and secure token refresh mechanisms.
The GraphQL Auth API is designed to be a complete solution for user authentication in modern web and mobile applications. It handles user registration, authentication, token management, and user data operations through a clean GraphQL interface.
Note: This documentation assumes you have basic familiarity with GraphQL concepts and operations. If you're new to GraphQL, we recommend reviewing the official GraphQL documentation before proceeding.
To use this API, you'll need to follow these steps to authenticate your requests:
Contact our team to receive a client ID and public key. These credentials are essential for accessing our API and ensuring secure communications.
All requests to the API must include the following header:
client_id: YOUR_CLIENT_ID
Use your provided public key to decrypt sensitive data and tokens returned by the API. This ensures that your authentication tokens remain secure during transmission.
Once you've obtained a JWT token from the signIn or signUp mutations, you should include it in subsequent requests that require authentication:
Authorization: Bearer YOUR_JWT_TOKEN
Our authentication system uses JWT (JSON Web Tokens) with the following characteristics:
All GraphQL operations are performed through a single endpoint:
POST https://central-auth-service.vercel.app/api
The API uses Apollo Server middleware to process GraphQL requests. All queries and mutations should be sent to this endpoint using the POST method with a JSON payload.
Important: All GraphQL operations must use POST requests. GET requests to the endpoint will return information about the API but will not process GraphQL operations.
GraphQL requests should be formatted as follows:
{
"query": "query { ... }" // or "mutation { ... }"
"variables": { } // optional variables object
}
The API provides the following query operations:
Verifies the validity of a JWT token and returns the associated user information.
query {
verifyToken(token: "your-jwt-token") {
id
email
}
}
Parameter | Type | Description |
---|---|---|
token | String! | JWT token to verify |
Generates a new refresh token from an existing token.
query {
generateRefreshToken(token: "your-jwt-token")
}
Parameter | Type | Description |
---|---|---|
token | String! | Existing JWT token |
Generates a new JWT token.
query {
generateToken
}
A simple test endpoint to verify API connectivity.
query {
sayHello {
message
status
}
}
The API provides the following mutation operations:
Registers a new user and returns authentication tokens.
mutation {
signUp(
email: "user@example.com",
password: "secure-password"
) {
access_token
refresh_token
message
status
error
}
}
Parameter | Type | Description |
---|---|---|
String! | User's email address | |
password | String! | User's password (min 8 characters) |
Authenticates an existing user and returns authentication tokens.
mutation {
signIn(
email: "user@example.com",
password: "secure-password"
) {
access_token
refresh_token
message
status
error
}
}
Parameter | Type | Description |
---|---|---|
String! | User's email address | |
password | String! | User's password |
Updates user information for an authenticated user.
mutation {
updateUser(
user_id: "user-id",
token: "jwt-token",
updated_data: {
email: "new-email@example.com",
password: "new-password"
}
) {
message
status
error
}
}
Parameter | Type | Description |
---|---|---|
user_id | String! | ID of the user to update |
token | String! | JWT token for authentication |
updated_data | Object! | Object containing fields to update |
Removes a user account.
mutation {
deleteUser(
user_id: "user-id",
token: "jwt-token"
)
}
Parameter | Type | Description |
---|---|---|
user_id | String! | ID of the user to delete |
token | String! | JWT token for authentication |
The API returns standardized error responses with appropriate HTTP status codes and descriptive messages to help troubleshoot issues.
Authentication errors typically include:
Error responses follow this structure:
{
"errors": [
{
"message": "Error description",
"extensions": {
"code": "ERROR_CODE",
"status": 400
}
}
]
}
Note: Always check the status and error fields in your response to handle errors gracefully in your application.