How to transfer data from page to another in node js - node.js

Hello there i am learning node.js and got stuck in a scenario.The flow is that in website user register himself and after successfully registering i will be sending him to route named create_profile which in is post request and also i want to send userId to create_profile route.In case if user close the website then if he agains open it and login then if profile is incomplete then i will be taking his userId and send to create_profile route.And after that to home page.What i was thinking to store session for user authentication in create profile page and login.This is because if login there can be tow cases : If user has successfully completed his profile then take him to home and store a global session there and second case it to take him to create profile as its incomplete then after successfully creating take him to home store global session for user authentication.But my confusion is to how to pass userId from login to create profile which is post request.Do i need to make temp session ? Please solve my issue i am confused how to solve this .

You can create a "profile_completed" coloumn in DB and set it as "false" (default), update it to "true" if user has completed the profile. While user login check if his profile is updated ,if yes send him to home else ask him to update.
You can pass user I'd to create_profile via request or get it from session storage you saved earlier

Related

How to access logged in user data in GAE?

I have a site dashboard on GAE standard node.js environment that uses login: admin option in handlers: element in my app.yaml file. This option makes google login window appear before accessing the site. Is it possible to get email and profile of user logged in?
Updates on Feb 2
Tested on my local server
I added login:required in app.yaml; it's a Python3 App but I did not use users api; I start the app with dev_appserver.py to make sure it uses the app.yaml file in the development environment; When I loaded the home page, it prompted me to sign in with test#example.com
I dumped the header output and it included the following
X-Appengine-User-Email: test#example.com
X-Appengine-User-Id: XXXXX
Original Answer
You can use the 'users' Api and call the function GetCurrentUser()
Example, if your code was in python, you'd have something like
from google.appengine.api import users
# Get information about the currently logged in user
users.GetCurrentUser()
# Extra - if you wanted to confirm this is an admin user
users.IsCurrentUserAdmin()
Since you're not using Python, see if the environment variable for USER_EMAIL exists. The source code for users api has the snippet below (so see if it works for you)
email = os.environ.get('USER_EMAIL', email)
_user_id = os.environ.get('USER_ID', _user_id)

How to do user authentication using a mysql databse

On a website:
After a successful login, how to stop sending the user to localhost/login cause he's already logged in, but send him instead to a localhost/index where there's a logout button.
Video reference (min 00:48)
https://youtu.be/DcB1Ge0HQ4I
That's a simple task ,,,did you create $_SESSION['loggedin'] = true;

How can I protect the loopback explorer by username and password?

I've just started using loopback4 and I would like to protect the /explorer from being public. The user would initially see a page where username and password must be entered. If successful, the user is redirected to /explorer where he can see all API methods (and execute them). If user is not authenticated, accessing the path /explorer would give a response of "Unauthorized". Is there a way to easily implement this?
There is issue talking about a GLOBAL default strategy is enabled for all routes including explorer in https://github.com/strongloop/loopback-next/issues/5758
The way is to specify a global metadata through the options:
this.configure(AuthenticationBindings.COMPONENT).to({
defaultMetadata: {
strategy: 'JWTStrategy'
}
})
this.component(AuthenticationComponent);
registerAuthenticationStrategy(this, JWTAuthenticationStrategy)
But in terms of enabling a single endpoint added by route.get(), it's not supported yet, see code of how explorer is registered. #loopback/authentication retrieves auth strategy name from a controller class or its members, but if the route is not defined in the controller, it can only fall back to the default options, see implementation

sailsjs waterlock get jwt on login successful and signup with more fields

I am using waterlock for authentication in sailsjs application. Everything is working fine. I need two customization.
Here to get token we need to follow two steps. http://example.com/auth/login and then http://example.com/user/jwt . What we need is token should return after successful login , i.e. http://example.com/auth/login should return token after successfull login.
When user try to login with credential by this URL : http://example.com/auth/login
If email id is not present waterlock create a new user with this email. We need to stop this because we have another mandatory fields to sign up a user like name, phone number etc.
Please tell me what needs to be done here.
I had exactly these issues yesterday as well and I was able to solve them:
I needed the user as well as the token on loggin. Go into your config/waterlock.js and look for the postAction on login and change the section to the following. Change success: 'default' to success: 'jwt'.
If you dont want to create a user if it doenst exist yet edit the following line in config/waterlock.js in the authMethod: createOnNotFound: false
I hope this helps.

login session script in nodejs using express.io

i want to create a login session script in nodejs.It should include username and password which is already stored in a database.if the user enter the id which is not in the database then it should show invalid id else it should redirect to another html page.There are lot of frameworks for nodejs but i haven't got any scripts for login session in nodejs.So please anyone can me help by giving me a full script to do these task.

Resources