I am using the full calendar io events as a json feed to call a .net 6 web api.
client side react code
<FullCalendar
initialView="dayGridMonth"
headerToolbar={{
left: "prev,next",
center: "title",
right: "dayGridMonth,timeGridWeek,timeGridDay"
}}
plugins={[dayGridPlugin, timeGridPlugin]}
events={`${process.env.REACT_APP_API_URL}/activities/getEventsByDate/${id}`}
eventClick={handleEventClick}
/>
the .net 6 web api controller.
[AllowAnonymous]
[HttpGet("GetEventsByDate/{routeName}")]
public async Task<ActionResult> GetRoomEvents(string routeName)
{
string start = Request.Query["start"];
string end = Request.Query["end"];
return HandleResult(await Mediator.Send(new GetEventsByDate.Query { RouteName = routeName, Start = start, End = end }));
}
however I would like to remove the AllowAnonymous and add my jwt bearer token. is their an option to do that using the full calendar io json feed?
With Typescript, you could use the following to fetch the api with your token added:
events: function (info, successCallback, failureCallback) {
const response = fetch('api/calendar', {
method: 'GET',
headers: {
"Authorization": 'Bearer ' + token)
}
});
const data = response;
successCallback(data);
failureCallback(data);
},
}