Back

Like system with Appwrite and NextJS

  • 0
  • Databases
  • Web
  • Self Hosted
loup
11 Jul, 2023, 19:33

Okay my actual like system is kinda energy-intensive regarding api requests. So im going for a fresh start. Ive got a collection movie_liked who gonna store all movie likes. Each document gonna as :

  • userID
  • movieID My first problem, is how prevent when liking, not have duplicate like for the same user with the same movie ? There no solution without making a check before (listDocument,....) ?
TL;DR
The user is having trouble with creating a like system using Appwrite and NextJS. They are getting an error about user_unauthorized when using the API route for liking a movie. They suspect that this is because the user token is not available in API routes. Another issue they have is preventing duplicate likes for the same user and movie. They are unsure if there is a solution without performing a check before the like is created. Solution: - The user should ensure that the user token is available in API routes to authorize the request. - To prevent duplicate likes, they can add a unique index on the userId and movieId fields in the
loup
11 Jul, 2023, 19:35

Ideally, I would like to have a single request to like or dislike a movie (like on Youtube, etc...) but I guess for that we need to have a custom backend with custom api request

Drake
11 Jul, 2023, 21:09

You can add 1 unique index on userId and movieId

loup
12 Jul, 2023, 07:36

Yeah my bad. But right now I try to create an api route in my NextJS app like this : /api/user/${userId}/movie/${movieId}/like for the like, but Ive got an error about user_unauthorized. That weird because its working with function, but not with api routes. I guess its because when using api routes, we dont have the user token to authorize the request

Drake
12 Jul, 2023, 15:55

You're right. The session is client side and there is no session server side

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more