Skip to content

Commit

Permalink
Merge pull request #216 from okto-hq/main
Browse files Browse the repository at this point in the history
react auth details fix and response ordering guideline
  • Loading branch information
oviawork authored Jan 9, 2025
2 parents 45cb87a + dfe4c06 commit 1fdb65c
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 1 deletion.
6 changes: 6 additions & 0 deletions content/docs/faq.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,14 @@ import { Accordion, Accordions } from 'fumadocs-ui/components/accordion';
<div style={{ display: "none" }}>
What should I do if I suspect an Okto API issue?
</div>
<div style={{ display: "none" }}>
Can I rely on the order of elements in API responses?
</div>

<Accordions>
<Accordion title="Can I rely on the order of elements in API responses?">
No, the order of elements in API responses is not guaranteed to remain consistent. Always search for elements by their specific properties (like network_name, symbol, etc.) rather than relying on array positions to ensure your code remains reliable.
</Accordion>
<Accordion title="What does this '[GET_ALL_ENTITIES] Request Failed: 'values' is missing in a filter' error mean?">
To resolve this error, go to your [Okto dashboard](https://dashboard.okto.tech/) and enable chains and tokens for your dApp.
</Accordion>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
title: Fetch Auth Details
description: "Retrieve authentication details of the currently logged-in user using the Okto SDK."
full: false
---

import { TypeTable } from 'fumadocs-ui/components/type-table';
import { Tab, Tabs } from 'fumadocs-ui/components/tabs';
import { Callout } from 'fumadocs-ui/components/callout';
import { Accordion, Accordions } from 'fumadocs-ui/components/accordion';
import { Icon as IIcon } from '@iconify/react';

import '../../../styles.css';

### Methods Overview

| Methods | Description |
|--------------------------------------------------------------|--------------------------------------------------|
| <sub><i>sync</i></sub> [`getAuthDetails`](#fetch-authentication-details-of-the-current-user) | Fetch authentication details of the current user |

<div className="method-box">

## Fetch authentication details of the current user

<sub><i>sync</i></sub> `getAuthDetails()`<a href="https://github.com/okto-hq/okto-sdk-react/blob/main/src/OktoProvider.tsx#L413" target="_blank" rel="noopener noreferrer" style= {{ textDecoration: "none" }}> <IIcon icon="lucide:external-link" height="17" style={{ display: 'inline-block', verticalAlign: 'middle' }} /></a> fetches the authentication details of the currently logged-in user.

### Parameters

There are no parameters for this function.

### Response

<Callout title="Success Response">

| Field Name | Type | Description |
|------------------|---------------------|-------------------------------------------------|
| `authToken` | `string` | Authentication token for API access |
| `refreshToken` | `string` | Token used to refresh authentication sessions |
| `deviceToken` | `string` | Token to identify the authenticated device |

</Callout>

<Accordions>
<Accordion title="Example">
<Tabs items={['Typescript']}>
<Tab value="Typescript">
```typescript
import { useOkto, type OktoContextType } from 'okto-sdk-react';

const { getAuthDetails } = useOkto() as OktoContextType;

const authDetails = getAuthDetails();

if (authDetails) {
console.log("Auth Token:", authDetails.authToken);
console.log("Refresh Token:", authDetails.refreshToken);
console.log("Device Token:", authDetails.deviceToken);
} else {
console.log("No user is authenticated.");
}
```
</Tab>
</Tabs>
</Accordion>
</Accordions>

</div>
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"title": "Verify Login & Logout",
"title": "Session Management",
"pages": [
"login",
"fetch-auth-details",
"logout"
]
}
65 changes: 65 additions & 0 deletions content/docs/sdk-overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,68 @@ Pick your SDK and start building.

Okto SDKs are designed to make Web3 development as seamless as possible. Dive into the detailed guides for each SDK and bring your applications to life with blockchain-powered features.

---

## Important Implementation Note

When working with Okto's APIs and SDKs, please note that the order of elements in responses is not guaranteed to remain consistent between different calls. Always write code that explicitly checks for specific properties rather than relying on the position of elements in the response.

### Example

Let's say you're fetching a user's wallets:

```typescript
// First API call might return:
{
"wallets": [
{
"network_name": "APTOS",
"address": "0x8d4e7a9cef2b53e35e0273e3ef4eccf114ae95ca7a75da79c6cbd416f9b12ab3",
"success": true
},
{
"network_name": "POLYGON",
"address": "0x156ba3f2d578B9Cd233f8D3fd07b7f78dC2D4921",
"success": true
},
{
"network_name": "SOLANA_DEVNET",
"address": "7KPHCFnLfh7KSqKVZwGr8dgTqwiAZBpLvmknhmmtXBCd",
"success": true
}
]
}

// A subsequent call might return the same data in a different order:
{
"wallets": [
{
"network_name": "POLYGON",
"address": "0x156ba3f2d578B9Cd233f8D3fd07b7f78dC2D4921",
"success": true
},
{
"network_name": "SOLANA_DEVNET",
"address": "7KPHCFnLfh7KSqKVZwGr8dgTqwiAZBpLvmknhmmtXBCd",
"success": true
},
{
"network_name": "APTOS",
"address": "0x8d4e7a9cef2b53e35e0273e3ef4eccf114ae95ca7a75da79c6cbd416f9b12ab3",
"success": true
}
]
}
```

**Incorrect Usage** - Don't rely on array positions:
```typescript
const polygonWallet = response.wallets[0].address; // Assumes Polygon wallet is first
```

**Correct Usage** - Find the wallet you need by its network name:
```typescript
const polygonWallet = response.wallets.find(wallet => wallet.network_name === 'POLYGON')?.address;
```

This principle applies to all list-type responses from Okto's APIs and SDKs. Always write code that explicitly looks for the data you need rather than assuming a specific order.

0 comments on commit 1fdb65c

Please sign in to comment.