This file contains hidden or 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 Button from "../components/Button"; | |
| export default function Login({ handleLogin, handleLoginChange }) { | |
| return ( | |
| <div> | |
| <div> | |
| <h1>Chattr</h1> | |
| <p>your chats, your way</p> | |
| </div> | |
This file contains hidden or 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 { useState } from "react"; | |
| import { useRouter } from "next/router"; | |
| function MyApp({ Component, pageProps }) { | |
| const [sender, setSender] = useState(""); | |
| const router = useRouter(); | |
| const handleLogin = (e) => { | |
| e.preventDefault(); | |
| router.push("/chat"); |
This file contains hidden or 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 '../styles/globals.css' | |
| import Pusher from 'pusher-js' | |
| function MyApp({ Component, pageProps }) { | |
| const {key, cluster} = process.env | |
| const pusher = new Pusher(key, { | |
| cluster | |
| }); |
This file contains hidden or 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 Pusher from "pusher"; | |
| export const pusher = new Pusher({ | |
| appId: process.env.app_id, | |
| key: process.env.key, | |
| secret: process.env.secret, | |
| cluster: process.env.cluster, | |
| useTLS: true, | |
| }); |
This file contains hidden or 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
| class MailingListController < ApplicationController | |
| def addUser | |
| # Setup the keys needed to access Mailchimp's API | |
| dc = 'us13' | |
| unique_id = "f1ff300381" | |
| url = "https://#{dc}.api.mailchimp.com/3.0/lists/#{unique_id}/members" | |
| api_key = "YOUR_API_KEY" | |
| # You need to pass the status:subscribed field to ensure the user is subscribed | |
| user_details = { |
This file contains hidden or 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 { parseCookies } from "../helpers/" | |
| export default function HomePage({ data }) { | |
| return ( | |
| <> | |
| <div> | |
| <h1>Homepage </h1> | |
| <p>Data from cookie: {data.user}</p> | |
| </div> | |
| </> | |
| ) |
This file contains hidden or 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
| // helpers/index.js | |
| import cookie from "cookie" | |
| export function parseCookies(req) { | |
| return cookie.parse(req ? req.headers.cookie || "" : document.cookie) | |
| } |
This file contains hidden or 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 { CookiesProvider } from "react-cookie" | |
| export default function MyApp({ pageProps }) { | |
| return ( | |
| <CookiesProvider> | |
| <Component {...pageProps} /> | |
| </CookiesProvider> | |
| ) | |
| } |
This file contains hidden or 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
| // pages/login.js | |
| import { useCookies } from "react-cookie" | |
| const Login = () => { | |
| const [cookie, setCookie] = useCookies(["user"]) | |
| const handleSignIn = async () => { | |
| try { | |
| const response = await yourLoginFunction(username) //handle API call to sign in here. | |
| const data = response.data | |
| setCookie("user", JSON.stringify(data), { | |
| path: "/", |
This file contains hidden or 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 React, {useRef} from 'react' | |
| const UseRefEx = () =>{ | |
| let usernameRefs = useRef([]); | |
| usernameRefs.current = [0,0,0,0].map( | |
| (ref, index) => usernameRefs.current[index] = React.createref() | |
| ) | |