Hey guys, Since day by day login using social media is getting popular so, Today I am going to discuss login with twitter step by step. So at first we need to create a twitter app, since we need client ID and client secret to intigrate in our code.
So go to Twitter and after login into your account create an app. And fill the basic details asked there and put callback url : http://localhost:3000/auth/twitter/callback for performing the task from local system. Once app is created over twitter, Copy API KEY and API SECRET which is required to authenticate the app.
Now lets come to the next step:
So let's have a look on our Package.json of our nodejs app. Where we have defined all the the dependencies of our application and basic information of the app.
Now let's move to the next part, where we will configure the credentials needed for our application.
In the above file we have provided the credentials needed for our app.
Now in the next step we will set import the mysql db.
CREATE TABLE user_master
(
user_id BIGINT(30) NOT NULL,
user_name VARCHAR(100) NOT NULL,
PRIMARY KEY(user_id)
);
We have just created the basic fields here, you can make as per the requirement of your application.
Now lets come to nodejs part Server.js, where intially we will have a serve.js file where every task happens. Let's have a look.
In the above file intially, we have included package of nodejs needed for any basic nodejs appliication. After that we have created mysql db connection and then se the ejs as view engine and set session secret. Below that passport related task goes on where we authenticate user with twitter and then check the user whether exists in our database or not. if not exists data is inserted into database. otherwise user login successfully.
At the end type node server.js At and type http://localhost:3000/ on your browser.
You can download the zipped code from here and then directly use after changing the basic settings.
Hope you get it easily. Thanks alot!