Skip to content

Instantly share code, notes, and snippets.

View gNaps's full-sized avatar

Gabriele Napoli gNaps

View GitHub Profile
@gNaps
gNaps / sign-out-action.component.tsx
Created August 25, 2023 12:37
twitch example api - sign out actions
"use client";
import { useEffect, useRef } from "react";
export default function SignOutAction({ deleteTokens }: any) {
const deleteTokensRef = useRef(deleteTokens);
useEffect(() => {
deleteTokensRef.current = deleteTokens;
});
@gNaps
gNaps / twitch.api.ts
Last active August 25, 2023 10:14
twitch example api - get stream follows
export const getFollowsStream = async (
userId: number,
accessToken: string,
after: string = "",
follows: any = []
) => {
const response = await fetch(
`${TWITCH_URL_API}/streams/followed?user_id=${userId}${
after ? `&after=${after}` : ""
}`,
@gNaps
gNaps / twitch.api.ts
Created August 25, 2023 10:13
twitch example api - get follows detail
export const getFollowsDetails = async (ids: any, accessToken: string) => {
const response = await fetch(`${TWITCH_URL_API}/users?${ids}`, {
headers: {
"Client-Id": process.env.NEXT_PUBLIC_CLIENT_ID,
Authorization: "Bearer " + accessToken,
},
});
const data = await response.json();
return data;
@gNaps
gNaps / twitch.api.ts
Created August 25, 2023 10:12
twitch example api - get follows
export const getFollows = async (
userId: number,
accessToken: string,
after: string = "",
follows: any = []
): Promise<any> => {
const response = await fetch(
`${TWITCH_URL_API}/users/follows?from_id=${userId}${
after ? `&after=${after}` : ""
}`,
@gNaps
gNaps / page.tsx
Last active August 25, 2023 10:06
twitch example api - homepage
import { getServerSession } from "next-auth";
import { authOptions } from "./api/auth/[...nextauth]/route";
import {
getFollows,
getFollowsDetails,
getFollowsStream,
} from "@/api/twitch-api";
import Topbar from "@/components/topbar.component";
import ChannelCard from "@/components/channel-card.component";
import { redirect } from 'next/navigation'
@gNaps
gNaps / page.tsx
Created August 25, 2023 10:02
twitch example api - login page
"use client";
import { signIn, useSession } from "next-auth/react";
import { redirect } from "next/navigation";
import { BsTwitch } from "react-icons/bs";
const Login = () => {
const { data: session } = useSession();
if (session) {
@gNaps
gNaps / layout.tsx
Created August 25, 2023 10:00
twitch example api - layout.tsx
export default async function RootLayout({
children,
}: {
children: React.ReactNode;
}) {
const session = await getServerSession(authOptions);
return (
<html lang="en">
<body className={inter.className}>
<Provider session={session}>{children}</Provider>
@gNaps
gNaps / SessionProvider.tsx
Created August 25, 2023 09:49
twitch example api - SessionProvider
'use client'
import { SessionProvider } from "next-auth/react"
export default function Provider ({
children,
session
}: {
children: React.ReactNode
session: any
@gNaps
gNaps / route.ts
Created August 25, 2023 09:41
twitch example api - [...nextauth]/route.ts
import NextAuth, { AuthOptions } from "next-auth";
export interface TwitchProfile extends Record<string, any> {
sub: string
preferred_username: string
email: string
picture: string
}
export default function TwitchProvider(
// Using min-width
// Small devices (landscape phones, 576px and up)
@media (min-width: 576px) { ... }
// Medium devices (tablets, 768px and up)
@media (min-width: 768px) { ... }
// Large devices (desktops, 992px and up)
@media (min-width: 992px) { ... }