Next.js Discord

Discord Forum

Need help deleting a post using axios

Unanswered
Rough harvester ant posted this in #help-forum
Open in Discord
Rough harvester antOP
Hello guys! Im creating a social media using next js, ive made the api aswell and it has this endpoint for deleting posts: DELETE http://localhost:3000/api/posts/123, where the number 123 is the post id, is there anyway i could show a delete button that only shows on posts posted by the user logged in, im using a bearer token system. Thanks in advance

8 Replies

Black carp
@Rough harvester ant If you want to show the delete button only to authenticated used..then firstly store the token in localstorage after user logged in and check if token available in local storage and show the button
Rough harvester antOP
@Black carp how can i check if a token is available in the local storage?
@Rough harvester ant <@462629609993797642> how can i check if a token is available in the local storage?
Black carp
const token=localstorage.getItem(“nameoftoken”)
Now for post u can check if token is available n valid then show button
Rough harvester antOP
but wouldnt that show on every post?
Black carp
U need to add multiple conditions like if the post author is same as logged user