supertokens / supertokens-react-native

React Native SDK for SuperTokens
Other
28 stars 11 forks source link

Add support for specifying Storage #96

Open Nikola-Milovic opened 1 year ago

Nikola-Milovic commented 1 year ago

It would be a nice option to be able to specify the storage type as long as it adheres to the Storage interface

for example, it would allow us to integrate expo-secure-store

import SuperTokens from 'supertokens-react-native';
import * as SecureStore from "expo-secure-store";
import "react-native-url-polyfill/auto";

const ExpoSecureStoreAdapter = {
    getItem: (key: string) => {
        return SecureStore.getItemAsync(key);
    },
    setItem: (key: string, value: string) => {
        SecureStore.setItemAsync(key, value);
    },
    removeItem: (key: string) => {
        SecureStore.deleteItemAsync(key);
    },
};

SuperTokens.init({
    apiDomain: "<YOUR_API_DOMAIN>",
    apiBasePath: "/auth",
    storage: ExpoSecureStoreAdapter
});

From the GoTrue JS SDK , this is the type they allow as storage

https://github.com/supabase/gotrue-js/blob/master/src/lib/types.ts#L48 https://github.com/supabase/gotrue-js/blob/master/src/lib/types.ts#L929

This would be a nice to have, it would possibly allow merging the supertokens libraries into a single supertokens-js library instead of having multiple implementations for RN and Web separately. Thoughts?

rishabhpoddar commented 1 year ago

These are excellent changes. We will consider these when we have more bandwidth. That being said, feel free to open a PR in our existing react native SDK to add this feature.

iway1 commented 1 year ago

this would be cool.. react-native-mmkv would be a great option as it is the fastest persistence library and is fully synchronous. Maybe that allows making some of the async methods in the library synchronous?