From b9bceadcf06b369edff7474172f4990ee2ac447b Mon Sep 17 00:00:00 2001 From: zaje1 Date: Thu, 9 Jan 2025 10:12:50 +0530 Subject: [PATCH 1/2] add: fetch auth details doc --- .../login-logout/fetch-auth-details.mdx | 67 +++++++++++++++++++ .../authenticate-users/login-logout/meta.json | 3 +- 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 content/docs/react-sdk/advanced-sdk-config/authenticate-users/login-logout/fetch-auth-details.mdx diff --git a/content/docs/react-sdk/advanced-sdk-config/authenticate-users/login-logout/fetch-auth-details.mdx b/content/docs/react-sdk/advanced-sdk-config/authenticate-users/login-logout/fetch-auth-details.mdx new file mode 100644 index 0000000..4e57cb1 --- /dev/null +++ b/content/docs/react-sdk/advanced-sdk-config/authenticate-users/login-logout/fetch-auth-details.mdx @@ -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 | +|--------------------------------------------------------------|--------------------------------------------------| +| sync [`getAuthDetails`](#fetch-authentication-details-of-the-current-user) | Fetch authentication details of the current user | + +
+ +## Fetch authentication details of the current user + +sync `getAuthDetails()` fetches the authentication details of the currently logged-in user. + +### Parameters + +There are no parameters for this function. + +### 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 | + + + + + + + + ```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."); + } +``` + + + + + +
\ No newline at end of file diff --git a/content/docs/react-sdk/advanced-sdk-config/authenticate-users/login-logout/meta.json b/content/docs/react-sdk/advanced-sdk-config/authenticate-users/login-logout/meta.json index da9201a..41259a4 100644 --- a/content/docs/react-sdk/advanced-sdk-config/authenticate-users/login-logout/meta.json +++ b/content/docs/react-sdk/advanced-sdk-config/authenticate-users/login-logout/meta.json @@ -1,7 +1,8 @@ { - "title": "Verify Login & Logout", + "title": "Session Management", "pages": [ "login", + "fetch-auth-details", "logout" ] } \ No newline at end of file From 643bd255aff4532bc85f5f779525bd77f4d9bcb8 Mon Sep 17 00:00:00 2001 From: zaje1 Date: Thu, 9 Jan 2025 10:13:40 +0530 Subject: [PATCH 2/2] add: response ordering guidelines in SDK Overview page and FAQ --- content/docs/faq.mdx | 6 ++++ content/docs/sdk-overview.mdx | 65 +++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/content/docs/faq.mdx b/content/docs/faq.mdx index 669599f..b6c41cd 100644 --- a/content/docs/faq.mdx +++ b/content/docs/faq.mdx @@ -36,8 +36,14 @@ import { Accordion, Accordions } from 'fumadocs-ui/components/accordion';
What should I do if I suspect an Okto API issue?
+
+ 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. + To resolve this error, go to your [Okto dashboard](https://dashboard.okto.tech/) and enable chains and tokens for your dApp. diff --git a/content/docs/sdk-overview.mdx b/content/docs/sdk-overview.mdx index 57fb229..2aa3a9d 100644 --- a/content/docs/sdk-overview.mdx +++ b/content/docs/sdk-overview.mdx @@ -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. \ No newline at end of file