JS20

Documentation

JS20 - Documentation

Logged-in endpoints

Create an endpoint that is only available to logged-in users.

app.addEndpoint({
    method: 'GET',
    path: '/example',
    outputSchema: {
        message: sString().type(),
    },
    // Require the user to be logged in
    isLoggedIn: true,
    run: (system) => {
        // Only users that are logged in can reach this point
        // All others will receive a 401 Unauthorized response
        return {
            message: `You are logged in as "${system.user.name}" with email "${system.user.email}".`
        }
    }
});

What's happening here?

  • isLoggedIn: true makes the endpoint require authentication
  • system.user contains information about the logged-in user
JS20