new info, I changed the permissions for the Public role to have find and findOne permissions
accessing http://localhost:1337/api/verification-tokens
works as expected.
data
0
id 17
documentId "ltl1mw5cz6qrsx6wu45jz9ls"
email "nmotos@ctsolutions.gr"
token "e47aa4ed-fd85-4fc4-ba2f-dbb3718d4fb3"
expires "2024-09-11T09:41:37.225Z"
createdAt "2024-09-11T08:41:37.242Z"
updatedAt "2024-09-11T09:06:38.342Z"
publishedAt "2024-09-11T09:06:38.321Z"
locale null
1
id 18
documentId "pqohw2dugczhohfew3bfr13g"
email "ertyu@fghj.hgfd"
token "hbvcxz"
expires "2024-09-10T21:45:00.000Z"
createdAt "2024-09-11T09:32:06.547Z"
updatedAt "2024-09-11T09:32:06.547Z"
publishedAt "2024-09-11T09:32:06.537Z"
locale null
meta
pagination
page 1
pageSize 25
pageCount 1
total 2
accessing http://localhost:1337/api/verification-tokens/18
returns a 404
error
status 404
name "NotFoundError"
message "Not Found"
details {}
not saying this is case closed but after a lot (and i mean a lot, basically about 3.5hrs) of debugging, trial and error, I changed backend/src/api/verification-token/controllers/verification-token.ts from
/**
* verification-token controller
*/
import { factories } from '@strapi/strapi'
export default factories.createCoreController('api::verification-token.verification-token');
to:
import { factories } from '@strapi/strapi'
export default factories.createCoreController('api::verification-token.verification-token', ({ strapi }) => ({
async findOne(ctx) {
const { id } = ctx.params;
console.log(`Fetching token with id: ${id}`);
const entity = await strapi.entityService.findOne('api::verification-token.verification-token', id);
if (!entity) {
console.log(`Token with id ${id} not found`);
return ctx.notFound('Token not found');
}
console.log(`Token found: ${JSON.stringify(entity)}`);
ctx.body = entity;
},
}));
and now findOne works completely as expected.
still unable to delete, however.
ok once again it’s the controller’s fault.
Could there be issues with controllers in general in v5 RC? should I open an issue abt this?
import { factories } from '@strapi/strapi';
export default factories.createCoreController('api::verification-token.verification-token', ({ strapi }) => ({
async findOne(ctx) {
const { id } = ctx.params;
console.log(`Fetching token with id: ${id}`);
try {
const entity = await strapi.entityService.findOne('api::verification-token.verification-token', id);
if (!entity) {
console.log(`Token with id ${id} not found`);
return ctx.notFound('Token not found');
}
console.log(`Token found: ${JSON.stringify(entity)}`);
ctx.body = entity;
} catch (error) {
console.log(`Error fetching token with id ${id}: ${error.message}`);
ctx.throw(500, 'Failed to fetch token');
}
},
async delete(ctx) {
const { id } = ctx.params;
console.log(`Deleting token with id: ${id}`);
try {
await strapi.entityService.delete('api::verification-token.verification-token', id);
console.log(`Token with id ${id} successfully deleted`);
ctx.send({ message: 'Token successfully deleted!' });
} catch (error) {
console.log(`Error deleting token with id ${id}: ${error.message}`);
ctx.throw(500, 'Failed to delete token');
}
},
}));
This custom controller works for both findOne and delete.
you can’t use the int ids in Strapi 5, you have to use the document ID
The reason it works when you use change the controller is you are bypassing the document service and going back to the legacy entity service (which is depricated)
yeah document service is new in Strapi 5 and gives string based CUIDs to all documents that the default routes use, they no longer accept the normal id
, that’s left there for legacy support
i stg i just noticed there’s id’s and documentIds at some random point like 30mins ago and wondered if thats important or not
yeah we don’t show the doc ID in the content manager (which is annoying) but you can find it if you go into the edit view and look at the address bar
are there any plans to add the documentId in the content manager mayhaps?
I think we have a github issue about it but it’s set as a low priority for the moment
It was one of the first things I noticed too
valid, its more of a quality of life thing
omfGGGGG this has been such a headache though
between having to basically rewrite most of my auth logic in the frontend and now this I’m FINALLY getting somewhere and this response (abt the docID) just feels like a deus ex machina
I cant believe I missed it. I saw the documentId in the docs instead of ID but not seeing it in the content manager I assumed it was just basically the same as ID.
you’re an absolute legend man, thank you immensly much