Server API
API routes
The server API routes exposed by default are:
POST /api/bedita/auth
to authenticate user/api/bedita/auth/logout
to logout userPATCH /api/bedita/auth/user
to update authenticated user attributes as name, surname, etc...POST /api/bedita/auth/reset
to request reset user passwordPATCH /api/bedita/auth/change
to change password after reset requestPOST /api/bedita/auth/optout
to delete userGET /api/bedita/*
to forward GET requests to BEdita API. SeeproxyEndpoints
configurationPOST /api/bedita/*
to forward POST requests to BEdita API. SeeproxyEndpoints
configurationPATCH /api/bedita/*
to forward PATCH requests to BEdita API. SeeproxyEndpoints
configurationDELETE /api/bedita/*
to forward DELETE requests to BEdita API. SeeproxyEndpoints
configurationPOST /api/bedita/_project
setup the project used from BEdita client. Seeprojects
configurtaion
Utils
There are some utils functions auto imported in server context.
beditaApiClient
beditaApiClient(event: H3Event): Promise<BEditaApiClient>
It resolves with the BEdita API client from @atlasconsulting/bedita-sdk.
export default defineEventHandler(async (event) => {
const client = await beditaApiClient(event);
const response = await client.get('/documents');
return response.data;
});
handleBeditaApiError
handleBeditaApiError(event: H3Event, error: AxiosError | H3Error | any): Promise<ApiResponseBodyError>
It helps to handle BEdita API errors setting response status and payload.
export default defineEventHandler(async (event) => {
try {
const client = await beditaApiClient(event);
const response = await client.get('/documents');
return response.data;
} catch (error) {
return handleBeditaApiError(event, error);
}
});
getProjectConfig
getProjectConfig(sessionData: SessionData, config: RuntimeConfig, property?: keyof BeditaProjectConf)
Return the configuration properties reading merged from current project and core properties.
recaptchaVerifyToken
recaptchaVerifyToken(token: string, action: string, throwError = true): Promise<boolean>
It needs to verify recapctha token sent by client. By default it throws a 400 Bad Request
if token validation fails.
export default defineEventHandler(async (event) => {
const body = await readBody(event);
await recaptchaVerifyToken(body?.recaptcha_token, 'my-action');
// do other stuff
});
getSessionConfig
getSessionConfig(): SessionConfig
Get the actual session configuration. It is useful to retrieve session.
export default defineEventHandler(async (event) => {
const session = await useSession(event, getSessionConfig());
// do stuff with session
});
filterUserDataToStore
filterUserDataToStore(data: UserAuth): UserDataStore
Filter user data and return a minimum data. Used to store in session cookie a miminal set of data.
export default defineEventHandler(async (event) => {
try {
const client = await beditaApiClient(event);
const response = await client.get('/auth/user');
return filterUserDataToStore(response?.data);
} catch (error) {
return handleBeditaApiError(event, error);
}
});