Save generated Identity in browser local storage

Hello,

I want to serialise and then deserialise the Identity:DelegationIdentity that we get from authClient.getIdentity(). The goal is to generate authClient from the identity saved in browser’s local storage.

Using identity.toJson() and then parsing the output does not work.

Also, AuthClient.create required identity of type SignIdentity.

How do I store the identity or better yet, the whole AuthClient in browser’s localstorage?

The identity should already be stored in the browser. The default used to be local storage but now it’s IndexedDB.

This thread might help: Keeping user logged in between browser refreshes (or: how to stringify authClient/agent/actor) - #4 by paulyoung

2 Likes
import { LocalStorage, AuthClient } from '@dfinity/auth-client';
const storage = new LocalStorage();
const authClient = AuthClient.create({ storage });

Should do what you’re looking for!

4 Likes