Overview
The 5Stack GraphQL API uses cookie-based authentication with credentials passed automatically by the browser. This provides a secure and seamless authentication experience for web applications.Authentication Method
Authentication is handled through HTTP cookies that are automatically included with requests when using thecredentials: 'include' option.
HTTP Requests
For standard GraphQL queries and mutations:WebSocket Connections
For real-time subscriptions:Admin Operations
For server-side admin operations, you can use the Hasura admin secret header:Your Hasura GraphQL admin secret for privileged operations
Authorization Hooks
The API uses Hasura’s webhook authorization system to validate requests and determine user permissions. The webhook validates:- User authentication status
- User roles (player, moderator, admin)
- Resource ownership and permissions
Error Responses
When authentication fails, you’ll receive one of these error messages:Unauthorized
Invalid Authorization Hook Response
Client Setup Example
Here’s a complete example of setting up an authenticated Apollo Client:Player Roles
The API recognizes the following user roles:Player
Standard user with access to their own data and public resources
Moderator
Can manage matches, tournaments, and moderate player actions
Admin
Full system access including server management and configuration
Session Management
Checking Authentication Status
You can check if a user is authenticated by querying their profile:Logging Out
Authentication cookies are managed by your auth service. To log out, clear the session cookie through your authentication endpoint.Security Best Practices
Use HTTPS Only
Use HTTPS Only
Always use HTTPS in production to protect authentication cookies from interception.
Secure Cookie Attributes
Secure Cookie Attributes
Keep Admin Secrets Safe
Keep Admin Secrets Safe
Never expose the Hasura admin secret to client-side code. Use environment variables and server-side operations only.
Validate User Input
Validate User Input
Always validate and sanitize user input before sending it to the API to prevent injection attacks.
Next Steps
Queries
Start querying player and match data
Mutations
Learn how to create and update resources