Hi,
I am building my custom plugin in the Strapi admin panel. I have created a new plugin via CLI.
When using getFetchClient
to get data from an endpoint it returns me a 401 Unauthorized
error and logs me out of the admin panel directly. The endpoint I am using is open for public
and authenticated
. When using axios
it returns me the data. But I was testing because with getFetchClient
because I want to protect the endpoint and I’ve read that with this method a Bearer token
is sent with the headers.
Can someone help me please?
In my plugin HomePage/index.js
I have:
import React, { useState, useEffect } from 'react';
import { getFetchClient } from '@strapi/helper-plugin';
import pluginId from '../../pluginId';
const HomePage = () => {
const { get } = getFetchClient();
const getGroups = async () => {
try {
const response = await get('/api/groups');
console.log(response.data);
} catch (error) {
// Handle error scenario
}
};
useEffect(() => {
getGroups();
}, []);
return (
<h1>My new plugin</h1>
);
};
export default HomePage;