Authentication
Authentication enables users to verify their identity, allowing you to control access to specific data and features in your application.
A typical authentication flow consists of these key steps:
- 1User provides credentials
- 2Server validates and issues an access token
- 3Client stores the token securely
- 4Client includes the token with API requests
- 5Server validates the token and grants access
This approach lets you implement secure authentication while keeping sensitive verification logic on your backend.
In Nordcraft, authentication is handled through API connections, allowing you to:
- Choose your preferred authentication system
- Integrate with existing providers
- Follow security best practices
- Support various authentication methods
Authentication should always be handled by your backend service. Nordcraft focuses on frontend development and provides secure ways to handle tokens received from authentication providers.
Storing access tokens
Access tokens represent user authorization and must be protected from unauthorized access. Store tokens in HTTP-only cookies for security:
- Cannot be accessed by client-side JavaScript
- Protected against cross-site scripting (XSS) attacks
- Automatically available in requests via the Nordcraft proxy
There are two approaches for storing access tokens securely in Nordcraft:
Use redirect authentication
For OAuth or third-party authentication providers that use redirects (like Supabase, Auth0 or Firebase):
- 1Redirect users to the authentication provider
- 2Configure the provider to redirect back to your application at
/.nordcraft?access_token=<Your access token>
- 3Nordcraft automatically stores this token in a secure HTTP-only cookie
- 4Optionally redirect users to a specific page after authentication using the query parameter
redirect_to=<URL>
Adding authentication to API requests
Once you have stored an access token, you will need to include it in your API requests to authenticate the user:
For bearer token authentication:
- 1Select your API in the data panel
- 2In the Headers tab of the API panel, click the + button to add a new header
- 3Select
Authorization
as the header name - 4The value is set by default to output
Bearer {{cookies.access_token}}
, usingConcatenate
andGet Http-Only Cookie
formulas. The value for theaccess_token
will be replaced in the Nordcraft proxy with the actual token.
API requests must be proxied through Nordcraft's Edge network for HTTP-only cookies to be included. This is enabled by default in the Advanced tab of your API configuration.
Authentication in the editor environment
Working with authenticated features in the Nordcraft editor requires a specific setup to securely share authentication between preview and editor environments.
Follow these steps to develop authenticated features:
- 1Install browser extension
- 2Log in through preview page
- Authentication must first occur in the preview environment. You can open the preview through the Bottom Bar
- With the extension installed, your authentication cookies are securely copied to the editor
- 3Develop in the editor
- Once authenticated, you can build and test protected features directly in the editor
- No need to log in separately for the editor environment
The browser extension is only required for development in the Nordcraft editor. Users of your published application will not need to install anything.
Security guidelines
Follow these security guidelines when implementing authentication:
- Short token lifetimes: Keep access tokens short-lived (hours, not days)
- Use refresh tokens: Implement refresh tokens for seamless token renewal. Most BaaS providers support this out of the box
- Secure token storage: Store tokens in HTTP-only, secure cookies
- Backend token validation: Ensure backend validates tokens for every request
- Proper logout: Clear tokens on both client and server upon logout
- Avoid client-side storage: Never store sensitive data in
localStorage
orsessionStorage
- No hardcoded tokens: Never store sensitive API keys or tokens in Nordcraft. Just store keys that are safe to store in a browser.