Skip to content

Instantly share code, notes, and snippets.

View gyfchong's full-sized avatar
🐝

Geoffrey Chong gyfchong

🐝
View GitHub Profile
@gyfchong
gyfchong / next-reusable-ssr-auth-check.js
Created December 19, 2021 12:27
How to make a reusable getServerSideProps function
// pages/protected.js
import protectRoute from "utils/protect-route";
export async function getServerSideProps({ req }) {
return await protectRoute(req, (user) => {
return { props: { user } };
});
}
// protect-route.js
const Checkbox = props => {
const CHECKBOX_NAME = props.name;
const CHECKBOX_VALUE = props.value;
// Using Formik Hooks, pass the checkbox name as the field we would like to use
const [field, meta, helper] = useField(CHECKBOX_NAME);
// Get the current checked state of the field based on its value
const isChecked = !!field.value[CHECKBOX_VALUE];
const handleChange = () => {
import { useEffect } from "react";
import { connect } from "getstream";
const App = () => {
useEffect(() => {
const initialiseStream = async () => {
// Fetch your token from the Express endpoint
@gyfchong
gyfchong / express-stream-token.js
Last active February 8, 2021 00:32
Express endpoint for generating a GetStream.io token
const { connect } = require("getstream");
// Get these values from your GetStream.io Dashboard
const client = connect(
"STREAM_KEY",
"STREAM_SECRET",
"APP_ID"
);
// Create an Express endpoint that recieves the UID for your authenticated user
{"lastUpload":"2021-12-14T12:08:18.231Z","extensionVersion":"v3.4.3"}
[alias]
ch = checkout
b = branch
ls = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate
p = pull
ps = push
m = merge
a = add
st = status
reset = reset --hard
Verifying that "gyfchong.id" is my Blockstack ID. https://onename.com/gyfchong

Keybase proof

I hereby claim:

  • I am gyfchong on github.
  • I am gyfchong (https://keybase.io/gyfchong) on keybase.
  • I have a public key whose fingerprint is 730E 2253 C57E BEC5 47E8 C2D8 6A00 3F15 146A 11AC

To claim this, I am signing this object: