Helpdesk auto-login
Let your own customers use the helpdesk from inside your app, already signed in
By default a customer who wants to see their requests on the helpdesk enters their email address and then a code we email them. If your customers already sign in to your app, that second sign-in is friction you do not need. With auto-login, your server tells Decuga who the customer is, Decuga gives back a session for them, and the SDK uses it in their browser. The customer sees no sign-in step, no code and no sign-out button.
How it works
- A customer is signed in to your app, and opens the page that has the helpdesk widget.
- Your page asks your server for a Decuga session (a call you write, which checks they are signed in to your app).
- Your server calls Decuga with the project API key:
POST /api/v1/projects/{projectId}/customer-sessionswith their email, and Decuga answers with a session. - Your server returns that answer to the page, and the page gives it to the SDK as the client's
session. - The widget shows their requests and their company's, with no sign-in step. When the session is about to end, the SDK asks your server again.
It is the same session a customer gets by entering a code, so what they may do is exactly what they could do after signing in the usual way, and nothing more.
Before you start
- The Business plan or above. Project API keys, and so this call, are on the Business plan. The helpdesk portal itself is on the Business plan too.
- A project API key, created under Integrations, API Keys. A key acts as the person who created it, and that person must have the permission to manage the service desk. See the API reference for how keys work.
- Your project id: the long id in the address of your public pages.
- At least one active helpdesk form, so the widget has something to show.
- A server of your own that can keep a secret and make an HTTPS call.
Step 1: ask for a session, from your server
Send the person's email, and optionally their name and company. Replace the key and the project id with your own.
curl -X POST https://decuga.com/api/v1/projects/$PROJECT_ID/customer-sessions \
-H "Authorization: Bearer $DECUGA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"email": "[email protected]",
"name": "Meera Rao",
"companyExternalId": "globex-1042"
}'| Field | Meaning |
|---|---|
email | Required. The person is found by it, or made a customer of the project if they are new. |
name | Optional. Used only when the customer is new. A customer who already exists keeps the name your team gave them. |
companyExternalId | Optional. Your own id for their company, the externalId of a company (see the Companies API). Puts them in that company. Leave out to keep whatever company they already have. |
The answer is 201 with the session. Pass all of it on to the browser:
{
"token": "eyJhbGciOi...",
"expiresAt": "2026-12-22T10:00:00Z",
"email": "[email protected]",
"name": "Meera Rao",
"customerId": "5c1e0c6e-...",
"companyId": "9a3f2d10-...",
"companyName": "Globex"
}An endpoint of your own, in Node
This is the whole of the server side: a route that checks who is signed in to your app, and swaps their email for a Decuga session. Use your own framework and your own check.
// POST /decuga-session (your server)
app.post('/decuga-session', requireSignedInUser, async (req, res) => {
const response = await fetch(
`https://decuga.com/api/v1/projects/${process.env.DECUGA_PROJECT_ID}/customer-sessions`,
{
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.DECUGA_API_KEY}`, // stays on the server
'Content-Type': 'application/json',
},
body: JSON.stringify({
email: req.user.email, // the user you already signed in
name: req.user.name,
companyExternalId: req.user.companyId, // your own id for their company
}),
},
)
if (!response.ok) return res.status(502).json({ error: 'Could not start the helpdesk session' })
res.json(await response.json()) // the whole session, as it came
})Step 2: give the session to the SDK
Pass a session when you make the client. It is either the session object as your server returned it, or a function that fetches one from your server. Prefer the function: the SDK calls it when it needs a session and again when the one it has is about to end, so a long-open page keeps working. With a fixed object the page has to be reloaded when it ends.
Web components, or any framework
import { DecugaClient } from '@decuga/client'
import '@decuga/elements'
const client = new DecugaClient({
projectId: 'YOUR_PROJECT_ID',
session: () => fetch('/decuga-session', { method: 'POST', credentials: 'include' }).then(r => r.json()),
})
const helpdesk = document.querySelector('decuga-helpdesk')
helpdesk.client = clientReact
import { DecugaProvider, DecugaHelpdesk } from '@decuga/react'
// Made once, outside the component, so it is not made again on every render
const getSession = () => fetch('/decuga-session', { method: 'POST', credentials: 'include' }).then(r => r.json())
export function Support() {
return (
<DecugaProvider projectId="YOUR_PROJECT_ID" session={getSession}>
<DecugaHelpdesk />
</DecugaProvider>
)
}Vue
import { createDecuga } from '@decuga/vue'
const getSession = () => fetch('/decuga-session', { method: 'POST', credentials: 'include' }).then(r => r.json())
app.use(createDecuga({ projectId: 'YOUR_PROJECT_ID', session: getSession }))
// <DecugaHelpdesk /> anywhere in the app now shows the signed-in customerThe session is kept in memory only. The SDK does not write it to local or session storage, because your site owns it. When you give a session, the widget has no sign-in step,signOut() does nothing, and sendCode() is refused. If your function fails, the widget says the customer could not be signed in and does not fall back to the emailed code.
What the customer sees
The same as a customer who has signed in with a code, without the sign-in and sign-out:
- All the active forms, including the ones kept for signed-in customers, with their own email already known.
- A list of the requests they have sent, and, when they belong to a company, a second list of the company's requests.
- Each request with its replies, where they can reply, and its attachments, which they can download.
- The ability to attach files to their requests (up to five, 25 MB each).
- Their email and company, shown as "Signed in as ...", with no Sign out button.
Companies
Send companyExternalId to put the customer in a company, so they see their company's requests. It is the externalId you give a company in the Companies API, so you use your own id everywhere. When it is given it decides the company, even if the customer's email domain matches another, and a customer who is in another company is moved to it. If no company has that id, the call fails with 404 and nobody is created. Leave it out to keep whatever company the person already has.
Security
- The API key stays on your server. It can do everything its owner can do in the project. There is no safe way to put it in a browser, so the call is not available to browsers (it does not allow cross-origin requests).
- The session token is a secret of one person. Hand it to that person's browser only. Do not log it, store it in a database or put it in a URL.
- You vouch for the person. Decuga signs in whoever you name, with no code. Check who they are in your own app first.
- A session lasts 30 days. It lets the person send requests, see their own and their company's, reply and attach files. It cannot use the API, and cannot see anyone else's requests.
- If a key may have leaked, delete it under Integrations, API Keys and make a new one: the old key can no longer ask for sessions. A session already given cannot be ended early, and works until it expires, the same as one made with an emailed code.
- Every session is logged with the name of the key that asked for it, and never with the token.
Errors
| Status | Meaning |
|---|---|
| 400 | The email is missing or not usable, or the name is longer than 100 characters. |
| 401 | No API key, or one that is wrong or has been revoked. |
| 403 | The key is for another project, the plan is below Business, the key's owner may not manage the service desk, or the helpdesk portal is not available on the project's plan. |
| 404 | No company has the id you sent as companyExternalId. |
| 429 | Too many requests: over the key's or the project's limit for the minute. Wait for Retry-After seconds. |
Every error is JSON, {"error": "..."}. The full reference, with the request and response fields, is in the API reference.
FAQ
Can I call it from the browser?
No. It needs the API key, which must never be in a browser. Call it from your server and return the answer to the page.
Does it replace the emailed code for everyone?
Only on pages where you give the client a session. The public portal on decuga.com, and any widget without a session, keeps the emailed code.
What if a customer's company changes?
Send the new companyExternalId the next time you ask for their session. They are moved, and their earlier requests move with them.
Does it send an email to the customer?
No.
Is there a separate SDK for it?
No. The server side is one HTTP call, shown above, that any language can make, so there is no package that could put the key in a browser. The browser packages gain the session option.
Where can I read more?
SDKs, Helpdesk portal, Companies REST API and the API reference.