# Sign-in & sign-out with NearFi

## Signing in

Once NearFi wallet object is available (see [here](https://docs.nearfi.finance/developer-guide/integrate-nearfi-dapp-browser-into-your-app/detecting-nearfi-wallet-provider-ready)), it is recommended for applications to request approval from users to sign-in the applications.\
\
Example code to request sign-in:<br>

```javascript
//request permission to call any function of your contract application 
const signInResponse = await window.nearFiWallet.requestSignIn({
  contractId: "your-contract-id", // the contract Id of your application
});
if (signInResponse.error) {
  console.log("failed to sign-in")
} else {
  console.log("sign-in success")
}

//you can also use promise to request
window.nearFiWallet.requestSignin({
  contractId: "your-contract-id", // the contract Id of your application
}).then(signInResponse => {})

// Or add `methodNames` if your contract application only needs permission for some of the methods
await window.nearFiWallet.requestSignIn({
  contractId: "your-contract-id", // the contract Id of your application
  methodNames: ["method1", "method2"]       // (optional) changed methods the app allowed to use
});
```

The response of `requestSignIn` function also has an access key information. More details on the response can be found [here](https://github.com/DegaLabs/wallet-selector/blob/37ca783acc64c141b521d264f1b8fca2e8945c21/packages/nearfi/src/lib/injected-nearfi.ts#L14).\
\
Once successfully signed in, function `window.nearFiWallet.isSignedIn()` will return `true`.

![](https://4011574344-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkVp3Ryzf5WpLSXDMEsvB%2Fuploads%2F4zCURHfASFHVKmCvgYpD%2Ftelegram-cloud-photo-size-5-6320929689539031326-y.jpg?alt=media\&token=d3c41cac-2ee1-41c9-a788-99caa1714589)

## Signing out

API `signOut` serve the function of singing out when a user wants to disconnect the wallet from the applications.

```javascript
await window.nearFiWallet.signOut();
```

![](https://4011574344-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FkVp3Ryzf5WpLSXDMEsvB%2Fuploads%2Fkr5AFabSQAtJ11lxDP9h%2Ftelegram-cloud-photo-size-5-6320929689539031325-y.jpg?alt=media\&token=22dbd8fe-68ab-4ba2-a3b6-8c6a3c2bf00d)
