Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I get access to my jwt first and then connect to socketiomiddleware? #43

Open
akshaykumar771 opened this issue Jun 18, 2020 · 0 comments

Comments

@akshaykumar771
Copy link

console.ignoredYellowBox = ["Remote debugger"];
import { YellowBox } from "react-native";
YellowBox.ignoreWarnings([
  "Unrecognized WebSocket connection option(s) `agent`, `perMessageDeflate`, `pfx`, `key`, `passphrase`, `cert`, `ca`, `ciphers`, `rejectUnauthorized`. Did you mean to put these under `headers`?"
]);
import React, { useState } from "react";
import { StyleSheet} from "react-native";
import * as Font from "expo-font";
import { AppLoading } from "expo";
import AppNavigation from "./navigation/AppNavigator";
import { createStore, applyMiddleware, combineReducers } from "redux";
import { Provider } from "react-redux";
import { setNavigator } from './navigationRef';
import ReduxThunk from 'redux-thunk';
import createSocketIoMiddleware from "redux-socket.io";
import {userReducer} from "./reducers/userReducer";
import {chatReducer} from "./reducers/chatReducer";

const store = createStore(combineReducers({userReducer, chatReducer}), applyMiddleware(ReduxThunk, socketIoMiddleware));

 let currentValue = store.getState().userReducer.token;
 const socket = io.connect('http://81.89.193.99:3001/chat', {
     query: {token: token} })
console.log("CuurentValue", currentValue);
const socketIoMiddleware = createSocketIoMiddleware(socket, "chat:");
const fetchFont = () => {
  return Font.loadAsync({ 
    "raleway-bold": require("./assets/fonts/Raleway-Bold.ttf"),
    ralewayBold: require("./assets/fonts/Raleway-Bold.ttf"),
    "roboto-regular": require("./assets/fonts/Roboto-Regular.ttf"),
    robotoRegular: require("./assets/fonts/Roboto-Regular.ttf"),
    Roboto_medium: require("./assets/fonts/Roboto-Regular.ttf"),
  });
};

export default function App() {
  const [fontLoaded, setFontLoaded] = useState(false);
  if (!fontLoaded) {
    return (
      <AppLoading
        startAsync={fetchFont}
        onFinish={() => setFontLoaded(true)}
        onError={(err) => {
          console.log(err);
        }}
      />
    );
  }
  return (
    <Provider store={store}>
      <AppNavigation ref = {(navigator) => {setNavigator(navigator)}} />
    </Provider>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: "#fff",
    alignItems: "center",
    justifyContent: "center",
  },
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant