Last active
February 8, 2021 01:36
-
-
Save gyfchong/27a5878aa554d61bc551bdc9e81fb525 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect } from "react"; | |
import { connect } from "getstream"; | |
const App = () => { | |
useEffect(() => { | |
const initialiseStream = async () => { | |
// Fetch your token from the Express endpoint | |
const streamToken = await fetch("/stream-token", { | |
headers: { | |
"Content-Type": "application/json", | |
uid: FIREBASE_USER_UID, | |
}, | |
}); | |
// Use the token in conjunction with your other Stream access keys | |
const client = connect(STREAM_KEY, streamToken, STREAM_APP_ID); | |
// Get that user feed combining the streamToken and your Firebase UID. | |
// This is particularly important, because you use the FIREBASE UID to generate your Stream Token, | |
// any time GetStream wants you to provide a `userId` it will always be a Firebase UID. | |
// | |
// In this case we are fetching the current logged in user, but if you wanted someone elses' stream, | |
// you will need to provide the Firebase UID of the other user. | |
const userFeed = await client.feed("user", FIREBASE_USER_UID, streamToken); | |
// Grab that feed. | |
const { results } = await feedClient.get(); | |
// After awaiting for so long, you can finally get your Feed on. | |
console.log(results); | |
}; | |
initialiseStream(); | |
}, []); | |
return ("App"); | |
}; | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment