Having upvotes only favors a positive vibe, and we favor the attitude: If you don't like a track, suggest something better instead of "disliking" something that exists. We have explicitly decided against downvotes because it clutters the user interface and we don't really see a benefit. We don't currently have this, but we thought about this as well. :) We tried to make the party joining process as friction-less as possible to get as many people as possible to vote.ĭoes your service allows skip to next song (immediately) using some down-voting ? i would really like the ability to set threshold of downvote to skip songs. You don't need an account to vote, just open the party and start voting. Think the other way around: wouldn't it be weird if you could skip, but not play? Skipping is usually tied to the ability of playback, so we don't currently have that. I suggest that non-premium users could participate the party and just effect the control of the songs (vote/skip.etc) To do that first thing we'd do is register the fastify-auth plugin using any Fastify instance.It works OK when using premium account □ With the fastify-auth plugin, we will tell fastify that whoever doesn't have a token should be rejected. With Fastify this is easy, Fastify has a plugin for easier authentication, and this authentication will be done in the preHandler function (in our routes opts). This means that we would need to authenticate the user for each of our private routes and this authentication needs to be done before any action can be performed. If access is granted, these users can perform any action within the routes with the same authentication. What makes a route private is the authentication that restricts unauthorized users from gaining access. These are the routes we will make private. These routes are from the last article I made. Some of our routes are going to be restricted to a specific type of users. In the cloud folder, create a file called admins.js, and add the followingĮnter fullscreen mode Exit fullscreen mode It is with this token he/she can access protected routes like that of deleting posts.Īlright then, let's start by creating our database array. As soon as he/she logs in a token will be generated for him/her. When a user creates an account, his/her details are appended to the array. The array can be empty initially or you can add placeholders. We will have a simple array of admins in a file, have it exported and used whenever and however we want. We are not connecting this API to a database, so like we did with the posts array in cloud/posts.js, that is how we would do the same for the admins. We will have a route for registering admins, and for logging them in. The first thing we want to do before protecting routes is to have a form of registering and logging in admins to the app (when connected to the front-end of course). So if you haven't installed the above dependencies you should do so now because we will be using them in this article.Ĭreating and Registering the Admins Routes But in the API's repo, fastify-auth is a dependency along with several others like jsonwebtoken, fastify-swagger (which we will get to in a second). In the previous article, I didn't talk about installing fastify-auth. If you cloned the API's repo, you wanna make sure you run npm install to install all dependencies and then test all endpoints in the test.http file to ensure it's working. Quickly let's go into our app and get things started. How would we easily protect routes in Fastify? Fastify's documentation is very detailed, I recommend you go through the docs after reading this article. What are we introducing? Today's article is going to focus on authentication. Or you can just clone this repo, and follow along. You should check out the previous article else I don't think you'll be able to follow along. We will improve on our CRUD API in this article. Hi there! Today's article is a continuation of my previous article on Fastify.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |