Skip to content
This repository has been archived by the owner on Apr 2, 2021. It is now read-only.

Commit

Permalink
Merge pull request #415 from shocknet/auth-and-gun-rpc-hotfix
Browse files Browse the repository at this point in the history
Auth and gun rpc hotfix
  • Loading branch information
Daniel Lugo authored Nov 25, 2020
2 parents 50a6c67 + f76d606 commit a2869aa
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 8 deletions.
13 changes: 10 additions & 3 deletions app/services/gun-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,19 @@ export const rifle = (
query: string,
publicKeyForDecryption?: string,
): ReturnType<typeof SocketIO> => {
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
}
7 changes: 3 additions & 4 deletions app/store/actions/auth.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { createAction } from '@reduxjs/toolkit'

export const authed = (data: {
alias: string
token: string
Expand All @@ -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) =>
({
Expand Down
21 changes: 21 additions & 0 deletions app/store/sagas/auth.ts
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions app/store/sagas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand All @@ -29,6 +30,7 @@ function* rootSaga() {
call(sentReqs),
call(receivedReqs),
call(sharedPosts),
call(auth),
])
}

Expand Down
2 changes: 1 addition & 1 deletion app/store/selectors/connection.ts
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a2869aa

Please sign in to comment.