Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app.post('/signin',(req,res) => {
- var loginKeyOptions = {
- method: 'GET',
- uri: 'http://124.82.79.235:58000/AuthAPI/api/auth/getloginkey',
- headers: {},
- json: true
- };
- var loginOptions = {
- method: 'POST',
- uri: 'http://124.82.79.235:58000/AuthAPI/api/auth/login',
- headers: {
- "Content-Type": "application/json",
- "key": ""
- },
- body: {},
- json: true
- };
- var roleOptions = {
- method: 'GET',
- uri: 'http://124.82.79.235:58000/UserAPI/api/Roles/my',
- headers: {
- "key": ""
- },
- json: true
- };
- var userEmail = req.body.email;
- var userPassword = req.body.password;
- rp(loginKeyOptions)
- .then((loginKeyBody) => {
- var key = loginKeyBody.data;
- var payload = { username: userEmail, password: userPassword}
- loginOptions.headers.key = key;
- loginOptions.body = payload;
- return rp(loginOptions)
- })
- .then((loginBody) => {
- console.log(loginBody);
- res.cookie('token',loginBody.data.token);
- res.cookie('userId',loginBody.data.userId);
- roleOptions.headers.key = loginBody.data.token;
- return rp(roleOptions)
- //res.redirect('/profile');
- })
- .then((roleBody) => {
- console.log('roleBody');
- console.log(roleBody);
- if (roleBody.roleName === "Buyer") {
- res.cookie('role',roleBody.roleName);
- res.redirect('/profile');
- } else if (roleBody.roleName === "Merchant") {
- res.cookie('role',roleBody.roleName);
- res.redirect('/merchant-centre');
- }
- })
- .catch((err) => {
- console.log(err.message);
- });
- });
Add Comment
Please, Sign In to add comment