Add didCompleteRequest event

This commit is contained in:
Christian Capeans 2023-04-19 12:54:10 +02:00
parent 943f6178de
commit 0740be570f
2 changed files with 16 additions and 2 deletions

View File

@ -1,6 +1,6 @@
'use strict';
const { castArray, isNil } = require('lodash/fp');
const { castArray, isNil, isEmpty } = require('lodash/fp');
const { UnauthorizedError, ForbiddenError } = require('@strapi/utils').errors;
const constants = require('../services/constants');
const { getService } = require('../utils');
@ -78,6 +78,13 @@ const authenticate = async (ctx) => {
const verify = (auth, config) => {
const { credentials: apiToken, ability } = auth;
strapi.telemetry.send('didCompleteRequest', {
eventProperties: {
authenticationMetod: auth?.strategy?.name || 'api-token',
isAuthenticated: !isEmpty(apiToken),
},
});
if (!apiToken) {
throw new UnauthorizedError('Token not found');
}

View File

@ -1,6 +1,6 @@
'use strict';
const { castArray, map, every, pipe } = require('lodash/fp');
const { castArray, map, every, pipe, isEmpty } = require('lodash/fp');
const { ForbiddenError, UnauthorizedError } = require('@strapi/utils').errors;
const { getService } = require('../utils');
@ -80,6 +80,13 @@ const authenticate = async (ctx) => {
const verify = async (auth, config) => {
const { credentials: user, ability } = auth;
strapi.telemetry.send('didCompleteRequest', {
eventProperties: {
authenticationMetod: auth?.strategy?.name,
isAuthenticated: !isEmpty(auth.credentials),
},
});
if (!config.scope) {
if (!user) {
// A non authenticated user cannot access routes that do not have a scope