WIP BOD-14 changes.
This commit is contained in:
@@ -24,10 +24,12 @@ export default class AppContainer extends Component {
|
||||
const wsLink = new WebSocketLink({
|
||||
uri: process.env.REACT_APP_GRAPHQL_ENDPOINT_WS,
|
||||
options: {
|
||||
//lazy: true,
|
||||
lazy: true,
|
||||
reconnect: true,
|
||||
connectionParams: () => {
|
||||
const token = localStorage.getItem("token");
|
||||
connectionParams: async () => {
|
||||
//const token = localStorage.getItem("token");
|
||||
const token = await auth.currentUser.getIdToken(true);
|
||||
console.log("token", token);
|
||||
if (token) {
|
||||
return {
|
||||
headers: {
|
||||
@@ -40,6 +42,7 @@ export default class AppContainer extends Component {
|
||||
});
|
||||
const subscriptionMiddleware = {
|
||||
applyMiddleware: async (options, next) => {
|
||||
console.log("SubMiddleware");
|
||||
options.authToken = await auth.currentUser.getIdToken(true);
|
||||
next();
|
||||
}
|
||||
|
||||
@@ -3,7 +3,10 @@ import { Avatar, Badge, Col, List, Row } from "antd";
|
||||
import React from "react";
|
||||
import { connect } from "react-redux";
|
||||
import { createStructuredSelector } from "reselect";
|
||||
import { openConversation, toggleChatVisible } from "../../redux/messaging/messaging.actions";
|
||||
import {
|
||||
openConversation,
|
||||
toggleChatVisible
|
||||
} from "../../redux/messaging/messaging.actions";
|
||||
|
||||
const mapStateToProps = createStructuredSelector({
|
||||
//currentUser: selectCurrentUser
|
||||
@@ -29,27 +32,29 @@ export function ChatConversationListComponent({
|
||||
</Col>
|
||||
</Row>
|
||||
<Row>
|
||||
<List
|
||||
dataSource={conversationList}
|
||||
renderItem={item => (
|
||||
<Badge count={item.messages_aggregate.aggregate.count || 0}>
|
||||
<List.Item
|
||||
key={item.id}
|
||||
style={{ cursor: "pointer" }}
|
||||
onClick={() =>
|
||||
openConversation({ phone_num: item.phone_num, id: item.id })
|
||||
}>
|
||||
<List.Item.Meta
|
||||
avatar={
|
||||
<Avatar src='https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png' />
|
||||
}
|
||||
title={item.phone_num}
|
||||
description='Some sort of RO info? '
|
||||
/>
|
||||
</List.Item>
|
||||
</Badge>
|
||||
)}
|
||||
/>
|
||||
<Col span={24}>
|
||||
<List
|
||||
dataSource={conversationList}
|
||||
renderItem={item => (
|
||||
<Badge count={item.messages_aggregate.aggregate.count || 0}>
|
||||
<List.Item
|
||||
key={item.id}
|
||||
style={{ cursor: "pointer" }}
|
||||
onClick={() =>
|
||||
openConversation({ phone_num: item.phone_num, id: item.id })
|
||||
}>
|
||||
<List.Item.Meta
|
||||
avatar={
|
||||
<Avatar src='https://zos.alipayobjects.com/rmsportal/ODTLcjxAfvqbxHnVXCYX.png' />
|
||||
}
|
||||
title={item.phone_num}
|
||||
description='Some sort of RO info? '
|
||||
/>
|
||||
</List.Item>
|
||||
</Badge>
|
||||
)}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
import { auth } from "../firebase/firebase.utils";
|
||||
|
||||
//used to ensure that there is always a fresh token.
|
||||
function minutesSince(date) {
|
||||
const now = new Date();
|
||||
const millisecondsSince = now - date;
|
||||
// Divide milliseconds by 1000 to get seconds
|
||||
// Divide seconds by 60 to get minutes
|
||||
return millisecondsSince / 1000 / 60;
|
||||
}
|
||||
|
||||
// Pass a different argument number to set a sooner/longer refresh time
|
||||
export function shouldRefreshToken(minutesBeforeShouldRefresh = 45) {
|
||||
const stringifiedRefreshTime = window.sessionStorage.getItem(
|
||||
`lastTokenRefreshTime`
|
||||
);
|
||||
const lastRefreshAt = new Date(stringifiedRefreshTime);
|
||||
const aboutToExpire =
|
||||
minutesSince(lastRefreshAt) >= minutesBeforeShouldRefresh;
|
||||
return aboutToExpire;
|
||||
}
|
||||
|
||||
|
||||
export async function refreshToken() {
|
||||
try {
|
||||
if (auth.user) {
|
||||
const idToken = await auth().currentUser.getIdToken(
|
||||
/* force refresh */ true
|
||||
);
|
||||
const now = new Date();
|
||||
window.localStorage.setItem(`lastTokenRefreshTime`, now);
|
||||
localStorage.setItem("token", idToken);
|
||||
console.log("Token refreshed.");
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
@@ -27,8 +27,8 @@ export function* signInWithEmail({ payload: { email, password } }) {
|
||||
try {
|
||||
const { user } = yield auth.signInWithEmailAndPassword(email, password);
|
||||
let token = yield user.getIdToken();
|
||||
localStorage.setItem("token", token);
|
||||
window.sessionStorage.setItem(`lastTokenRefreshTime`, new Date());
|
||||
// localStorage.setItem("token", token);
|
||||
//window.sessionStorage.setItem(`lastTokenRefreshTime`, new Date());
|
||||
yield put(
|
||||
signInSuccess({
|
||||
uid: user.uid,
|
||||
@@ -55,8 +55,8 @@ export function* isUserAuthenticated() {
|
||||
return;
|
||||
}
|
||||
let token = yield user.getIdToken();
|
||||
localStorage.setItem("token", token);
|
||||
window.sessionStorage.setItem(`lastTokenRefreshTime`, new Date());
|
||||
//localStorage.setItem("token", token);
|
||||
//window.sessionStorage.setItem(`lastTokenRefreshTime`, new Date());
|
||||
|
||||
yield put(
|
||||
signInSuccess({
|
||||
|
||||
Reference in New Issue
Block a user