Example
Example copied to clipboard
Potentially error
in the session recovery example, potential error
application/api/auth.2/restore.js
({
access: 'public',
method: async ({ token }) => {
const restored = context.client.restoreSession(token);
if (restored) return { status: 'logged' };
const data = await api.auth.provider.readSession(token);
return { status: data ? 'logged' : 'not logged' };
},
});
If the token is not in sessions, we check it in the database, but after that we don't add it to sessions.
Example: context.client.startSession(token, data);
Currently the problem is still exist. Way to reproduce:
-
node server.js - Open browser http://localhost:8000
- Open DevConsole: network tab there, click on
apiws request and go to"Messages" tab - Check that one of the initial messages was
{type: "call", id: 2, method: "auth/signin",…}and the callback was{type: "callback", id: 2, result: {status: "logged"}} - Type in console
await api.example.counter();that reqesting logged endpoint - You will receive successful answer.
- Reload the browser tab.
- Check that one of the initial messages was
{type: "call", id: 2, method: "auth/restore",…}and the callback was{type: "callback", id: 2, result: {status: "logged"}} - Call again
await api.example.counter(); - Result:
error: {message: "Forbidden", code: 403}.
After deleting the token from localStorage and repeated clean auth/signin it works as expected again.