mirror of
https://github.com/inaturalist/iNaturalistReactNative.git
synced 2026-06-20 21:48:42 -04:00
* Rename some functions and variables
* Rename function
* Revert to original timeout for tokens
* Get JWT for a 401 or 403 http errors in the react-query QueryClient retry handler
* Log API error to new logger
* Fetch token on every render in useApiToken hook
* Remove commented code
* Add comment
* Remove useEffect from useApiToken
* Revert "Remove useEffect from useApiToken"
This reverts commit 9cf1e0c0bc.
35 lines
1023 B
JavaScript
35 lines
1023 B
JavaScript
import i18next from "i18next";
|
|
import inatjs from "inaturalistjs";
|
|
import RNSInfo from "react-native-sensitive-info";
|
|
|
|
import { makeResponse } from "../factory";
|
|
|
|
async function signOut( ) {
|
|
i18next.language = undefined;
|
|
// This is the nuclear option, maybe revisit if it's a source of bugs
|
|
global.realm.write( ( ) => {
|
|
global.realm.deleteAll( );
|
|
} );
|
|
await RNSInfo.deleteItem( "username" );
|
|
await RNSInfo.deleteItem( "jwtToken" );
|
|
await RNSInfo.deleteItem( "jwtGeneratedAt" );
|
|
await RNSInfo.deleteItem( "accessToken" );
|
|
}
|
|
|
|
async function signIn( user ) {
|
|
await RNSInfo.setItem( "username", user.login );
|
|
await RNSInfo.setItem( "jwtToken", "yaddayadda" );
|
|
await RNSInfo.setItem( "jwtGeneratedAt", Date.now( ).toString( ), {} );
|
|
await RNSInfo.setItem( "accessToken", "yaddayadda" );
|
|
inatjs.users.me.mockResolvedValue( makeResponse( [user] ) );
|
|
user.signedIn = true;
|
|
global.realm.write( ( ) => {
|
|
global.realm.create( "User", user, "modified" );
|
|
} );
|
|
}
|
|
|
|
export {
|
|
signIn,
|
|
signOut
|
|
};
|