From 74f48229fc53be06b18dbba0e446ae1a2fa679d4 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 24 Mar 2021 17:53:09 -0500 Subject: [PATCH] Fix streaming access token --- app/soapbox/features/ui/index.js | 3 ++- app/soapbox/stream.js | 3 ++- app/soapbox/utils/auth.js | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 app/soapbox/utils/auth.js diff --git a/app/soapbox/features/ui/index.js b/app/soapbox/features/ui/index.js index 194f2cdc0..8b5c1318c 100644 --- a/app/soapbox/features/ui/index.js +++ b/app/soapbox/features/ui/index.js @@ -40,6 +40,7 @@ import Icon from 'soapbox/components/icon'; import { isStaff } from 'soapbox/utils/accounts'; import ChatPanes from 'soapbox/features/chats/components/chat_panes'; import ProfileHoverCard from 'soapbox/components/profile_hover_card'; +import { getAccessToken } from 'soapbox/utils/auth'; import { Status, @@ -111,7 +112,7 @@ const mapStateToProps = state => { hasComposingText: state.getIn(['compose', 'text']).trim().length !== 0, hasMediaAttachments: state.getIn(['compose', 'media_attachments']).size > 0, dropdownMenuIsOpen: state.getIn(['dropdown_menu', 'openId']) !== null, - accessToken: state.getIn(['auth', 'user', 'access_token']), + accessToken: getAccessToken(state), streamingUrl: state.getIn(['instance', 'urls', 'streaming_api']), me, account, diff --git a/app/soapbox/stream.js b/app/soapbox/stream.js index 4622df344..cd6a16bf7 100644 --- a/app/soapbox/stream.js +++ b/app/soapbox/stream.js @@ -1,13 +1,14 @@ 'use strict'; import WebSocketClient from 'websocket.js'; +import { getAccessToken } from 'soapbox/utils/auth'; const randomIntUpTo = max => Math.floor(Math.random() * Math.floor(max)); export function connectStream(path, pollingRefresh = null, callbacks = () => ({ onConnect() {}, onDisconnect() {}, onReceive() {} })) { return (dispatch, getState) => { const streamingAPIBaseURL = getState().getIn(['instance', 'urls', 'streaming_api']); - const accessToken = getState().getIn(['auth', 'user', 'access_token']); + const accessToken = getAccessToken(getState()); const { onConnect, onDisconnect, onReceive } = callbacks(dispatch, getState); let polling = null; diff --git a/app/soapbox/utils/auth.js b/app/soapbox/utils/auth.js new file mode 100644 index 000000000..3fb5e7483 --- /dev/null +++ b/app/soapbox/utils/auth.js @@ -0,0 +1,4 @@ +export const getAccessToken = state => { + const me = state.getIn(['auth', 'me']); + return state.getIn(['auth', 'users', me, 'access_token']); +};