worldwide-asset-exchange / waxjs

Javascript API for integration with the WAX Cloud Wallet.
MIT License
127 stars 103 forks source link

Waxjs manual login #172

Open tokmak0 opened 1 year ago

tokmak0 commented 1 year ago

I am trying to create a login system using waxjs. Now I have succeeded in this and I can also auto-login. However, the problem is, I am using nextjs 13 and how can I verify the identity of the user on the server side? Also, how can I auto-login the user myself? An example code would be very useful to me. Thank you. Code:

const  wax = new waxjs.WaxJS({
        rpcEndpoint: 'https://wax.greymass.com',
});

// I  need to remember the user on other pages too
const userAccount = wax.login(); 
niksad8 commented 1 year ago

for the verification part there is a verify endpoint you can use waxProof function to do this , also when you login you can pass a nonce https://github.com/worldwide-asset-exchange/waxjs/blob/develop/src/index.ts#L132 this will allow you to get a verification signature, once the user logs in you can then use the users public key to verify the signature as being acurate, you can do this check on the backend too, to be safe.

regarding the auto login, the general work flow is once the user logins to your website you store the wallet name in localstorage, or server session. you can then use that to execute transactions on behalf on the user. usually you will need to execute the function isAutoLoginAvailable this way we can do it.

tokmak0 commented 1 year ago

@niksad8 Thanks for information. But I didn't understand how to verify this signature on the server. For example, can I keep the software signature on the client? Can you give sample code?

rdewilder commented 11 months ago

@tokmak0 To verify the user on the serverside you can do the following:

Client const proof = await wax.waxProof('nonce', true)

send the contents of proof to the server

Server Validate the proof sent by client: https://github.com/worldwide-asset-exchange/waxjs?tab=readme-ov-file#manual-verification-of-signature

Make sure you use the active key from the proof.wax account when verifying the signature.