Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

citizens/register #13

Open
sleekLancelot opened this issue Oct 2, 2020 · 5 comments
Open

citizens/register #13

sleekLancelot opened this issue Oct 2, 2020 · 5 comments
Assignees
Labels
help wanted Extra attention is needed

Comments

@sleekLancelot
Copy link

sleekLancelot commented Oct 2, 2020

In the register controller(/api/v1/citizen/register), after registration and you 'citizen.save()', can you make it return a token just like it does in the login controller? The way it is now it seems, one would have to login again after registering.

you can make it something like:

await citizen.save();
const payload = {
       id: citizen._id,
     };
     const token = jwt.sign(payload, mySecrete, { expiresIn: "1hr" });

     res.json({
       msg: "you are now logged in",
       token,
     });
@sleekLancelot sleekLancelot added the help wanted Extra attention is needed label Oct 2, 2020
@udofia2
Copy link
Member

udofia2 commented Oct 2, 2020

Thanks for raising the issue.
It is correct that after registration, the citizen will have to login.
The token is signed during login

@udofia2
Copy link
Member

udofia2 commented Oct 2, 2020

The will be form for registration.
After which the user will have to be redirected to the login page

@sleekLancelot
Copy link
Author

sleekLancelot commented Oct 2, 2020

Thanks for raising the issue.
It is correct that after registration, the citizen will have to login.
The token is signed during login

yes, I was talking of also returning a signed token after registration, I might be mistaking but that is possible too right!?.
So the '/api/v1/citizen/profile/:id' controller can fetch the citizen and offence pertaining to the id in the header.
Registering and then having to subsequently login with the newly registered details might give poor mark on user-experience.

@sleekLancelot
Copy link
Author

Also, when we hit 'GET /api/v1/citizen/profile/:id'
the id parameter in the req will course a lot of problems, its suppose to be a the citizen._id right?
but i can't get the citizen details until this code runs const citizen = await Citizens.findOne({ _id: req.params.id });
And that code only runs on a GET request to /api/v1/citizen/profile/:id which requires a param of the citizen id,whc i dont have yet

so i suggest you change the controller url from /api/v1/citizen/profile/:id to /api/v1/citizen/profile
And
const citizen = await Citizens.findOne({ _id: req.params.id });
to something like :
const citizen= await Citizens.findById(req.user, '-password'); res.json({ citizen});

@udofia2 udofia2 added this to To do in criminal-registry-BACKEND via automation Oct 16, 2020
@udofia2
Copy link
Member

udofia2 commented Oct 22, 2020

sorry for the delay.
And thank you for your patience
The issues are being attended to

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
Development

No branches or pull requests

2 participants