diff --git a/app/services/gun-rpc.ts b/app/services/gun-rpc.ts index 47cb81c5..5215254d 100644 --- a/app/services/gun-rpc.ts +++ b/app/services/gun-rpc.ts @@ -26,12 +26,19 @@ export const rifle = ( query: string, publicKeyForDecryption?: string, ): ReturnType => { - const socket = SocketIO(`http://${host}/gun`, { + const opts = { query: { $shock: query, - publicKeyForDecryption, }, - }) + } + + if (publicKeyForDecryption) { + // else "undefined" string will arrive at server 💩 + // @ts-expect-error + opts.publicKeyForDecryption = publicKeyForDecryption + } + + const socket = SocketIO(`http://${host}/gun`, opts) return socket } diff --git a/app/store/actions/auth.ts b/app/store/actions/auth.ts index 761b7ef9..7e7b7ce2 100644 --- a/app/store/actions/auth.ts +++ b/app/store/actions/auth.ts @@ -1,3 +1,5 @@ +import { createAction } from '@reduxjs/toolkit' + export const authed = (data: { alias: string token: string @@ -8,10 +10,7 @@ export const authed = (data: { data, } as const) -export const tokenDidInvalidate = () => - ({ - type: 'tokenDidInvalidate', - } as const) +export const tokenDidInvalidate = createAction('tokenDidInvalidate') export const hostWasSet = (host: string) => ({ diff --git a/app/store/sagas/auth.ts b/app/store/sagas/auth.ts new file mode 100644 index 00000000..69faaa63 --- /dev/null +++ b/app/store/sagas/auth.ts @@ -0,0 +1,21 @@ +import { takeEvery } from 'redux-saga/effects' +import Logger from 'react-native-file-log' + +import * as Actions from '../actions' +import { navigate } from '../../services' +import { AUTH } from '../../routes' + +function* handleTokenInvalidation() { + try { + navigate(AUTH) + } catch (err) { + Logger.log(`Error inside handleTokenInvalidation* ()`) + Logger.log(err.message) + } +} + +function* rootSaga() { + yield takeEvery(Actions.tokenDidInvalidate, handleTokenInvalidation) +} + +export default rootSaga diff --git a/app/store/sagas/index.ts b/app/store/sagas/index.ts index 141b7fe4..70320cd5 100644 --- a/app/store/sagas/index.ts +++ b/app/store/sagas/index.ts @@ -13,6 +13,7 @@ import chats from './chats' import sentReqs from './sent-reqs' import receivedReqs from './received-reqs' import sharedPosts from './shared-posts' +import auth from './auth' function* rootSaga() { yield all([ @@ -29,6 +30,7 @@ function* rootSaga() { call(sentReqs), call(receivedReqs), call(sharedPosts), + call(auth), ]) } diff --git a/app/store/selectors/connection.ts b/app/store/selectors/connection.ts index 7e4db87d..d41b2963 100644 --- a/app/store/selectors/connection.ts +++ b/app/store/selectors/connection.ts @@ -1,4 +1,4 @@ import { State } from '../reducers' export const isOnline = (state: State): boolean => - Date.now() - state.connection.lastPing < 6000 + Date.now() - state.connection.lastPing < 9000