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

Should ctx.state.user contains password? #166

Open
fancyoung opened this issue Sep 23, 2021 · 1 comment
Open

Should ctx.state.user contains password? #166

fancyoung opened this issue Sep 23, 2021 · 1 comment

Comments

@fancyoung
Copy link

When I use koa-passwort with passport-local,
user database info such as password are in ctx.state.user.

What's ctx.state.user used for ?
Should I wrap(remove password) it before pass to frontend, or I made some mistake ?

@rkusa
Copy link
Owner

rkusa commented Sep 27, 2021

passport-local usually puts puts the username and password into req.user. koa has ctx.state for custom data, which is why the object is put into ctx.state.user instead.

What's ctx.state.user used for ?
Should I wrap(remove password) it before pass to frontend, or I made some mistake ?

Yes, you should definitely not return the password to the frontend (and also don't have it as plain text available in the database object). I think most passport-local usages serialize and deserialize the user by its ID (and not the whole object), see e.g. https://github.com/rkusa/koa-passport-example/blob/master/auth.js#L11-L13).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants