Skip to content

Commit d819af8

Browse files
docs: auth getIdentityOnce (#454)
Signed-off-by: David Dal Busco <david.dalbusco@outlook.com>
1 parent d62e551 commit d819af8

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

docs/build/authentication/development.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,33 @@ const unsubscribe = authSubscribe((user: User | null) => {
102102
unsubscribe();
103103
```
104104

105+
---
106+
107+
## Imperative Access to Identity
108+
109+
For advanced use cases, you may need direct access to the user's identity. You can use `getIdentityOnce` to retrieve the identity if the user is currently authenticated.
110+
111+
:::caution
112+
113+
Use this function **imperatively only**. Do **not** persist the identity in global state or store it for reuse. This function is intended for short-lived, one-time operations only.
114+
115+
:::
116+
117+
```ts
118+
import { getIdentityOnce } from "@junobuild/core";
119+
120+
// Returns null if the user is not authenticated
121+
const identity = await getIdentityOnce();
122+
123+
if (identity !== null) {
124+
// Use the identity to perform calls on the Internet Computer
125+
}
126+
```
127+
128+
Typical use case for this function is to enable developers to implement custom features for the Internet Computer:
129+
130+
- Passing the identity to temporarily create an actor or agent to call a canister
131+
- Signing a message or making a one-time authenticated call
132+
105133
[Internet Identity]: ../../terminology.md#internet-identity
106134
[NFID]: ../../terminology.md#nfid

0 commit comments

Comments
 (0)