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

Documentation addition for working with JSON #28

Open
Vlix opened this issue Nov 8, 2020 · 0 comments
Open

Documentation addition for working with JSON #28

Vlix opened this issue Nov 8, 2020 · 0 comments

Comments

@Vlix
Copy link
Collaborator

Vlix commented Nov 8, 2020

After talking to someone who used password-instances, it's still somewhat annoying to have to make a field Text, just because you want to also use it with ToJSON to send between services.
It might be a good idea to give an example to make this more convenient, because they did say they think it's a good idea not to allow Password to be turned into JSON for security's sake.

I think something in the documentation near the JSON instances like the following would make it easier for users to switch between Text and Password within other types:

Instead of:

data LoginForm = LoginForm
  { loginUsername :: UserName
  , loginPassword :: Text
  }

and then changing the loginPassword to Password just before hashing or checking, do the following:

data LoginForm a = LoginForm
  { loginUserName :: UserName
  , loginPassword :: a
  } deriving (Show, Functor)

This way, you can have a ToJSON instance for LoginForm while still using LoginForm Password everywhere in your code, while just doing:

unsafeShowPassword <$> loginForm :: LoginForm Text

just before sending it over the wire, and you can still just get the password straight from JSON because of the FromJSON instance.

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

1 participant