-
Notifications
You must be signed in to change notification settings - Fork 1
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
Pf/dapp auth scaffold #30
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
open Ethers.Utils | ||
|
||
let setSignInData = (~ethAddress: string, ~ethSignature: string) => Dom.Storage2.localStorage->Dom.Storage2.setItem(ethAddress, ethSignature) | ||
|
||
@react.component | ||
let make = () => { | ||
let signer = RootProvider.useSignerExn() | ||
let userAddress = RootProvider.useCurrentUserExn() | ||
let { setIsAuthorized } = AuthProvider.useAuthStatus() | ||
<button | ||
onClick={(_) => { | ||
let _ = Ethers.Wallet.signMessage( | ||
signer, | ||
`flows.finance-signin-string:${userAddress->ethAdrToStr}`, | ||
)->JsPromise.map(result => { | ||
setSignInData(~ethAddress=userAddress->ethAdrToLowerStr, ~ethSignature=result->Js.String2.make) | ||
setIsAuthorized(_ => true) | ||
}) | ||
}} | ||
> | ||
{"Authenticate"->React.string} | ||
</button> | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, cool, I wrote my own bindings to this last time, convenient that it already exists :)