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 jwt from "jsonwebtoken"; | |
import cookie from "cookie"; | |
function createJwtCookie(userId, email) { | |
const token = jwt.sign({ userId, email }, process.env.REACT_APP_JWT_TOKEN, { | |
expiresIn: "10 days", | |
}); | |
const jwtCookie = cookie.serialize("jwt", token, { | |
secure: process.env.NETLIFY_DEV !== "true", | |
httpOnly: 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
import { MongoClient } from "mongodb"; | |
function createClient() { | |
const client = new MongoClient( | |
`mongodb+srv://admin:${process.env.REACT_APP_DB_PASSWORD}@cluster0.si7bk.mongodb.net/test?retryWrites=true&w=majority`, | |
{ | |
useNewUrlParser: true, | |
useUnifiedTopology: true, | |
}, | |
(err) => { |
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 cookie from "cookie"; | |
import jwt from "jsonwebtoken"; | |
export async function handler(event) { | |
const cookies = event.headers.cookie && cookie.parse(event.headers.cookie); | |
if (!cookies || !cookies.jwt) { | |
return { | |
statusCode: 401, | |
body: JSON.stringify({ | |
msg: "Unauthorized,JWT cookie is missing", |
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 cookie from "cookie"; | |
import jwt from "jsonwebtoken"; | |
export async function handler(event) { | |
const cookies = event.headers.cookie && cookie.parse(event.headers.cookie); | |
if (!cookies || !cookies.jwt) { | |
return { | |
statusCode: 401, | |
body: JSON.stringify({ | |
auth: false, |
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 { clearCookie } from "../helpers/jwt-helper"; | |
export async function handler() { | |
return { | |
statusCode: 200, | |
headers: { | |
"Set-Cookie": clearCookie(), | |
"Content-Type": "application/json", | |
}, | |
body: JSON.stringify({ message: "Logged out successfully" }), |
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 bcrypt from "bcryptjs"; | |
import { JsonWebTokenError } from "jsonwebtoken"; | |
import { createClient } from "../helpers/db-helper"; | |
import { createJwtCookie } from "../helpers/jwt-helper"; | |
export async function handler(event) { | |
const dbClient = createClient(); | |
let errorStatusCode = 500; | |
try { |
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 bcrypt from "bcryptjs"; | |
import { createClient } from "../helpers/db-helper"; | |
import { createJwtCookie } from "../helpers/jwt-helper"; | |
export async function handler(event) { | |
const dbClient = createClient(); | |
let errorStatusCode = 500; | |
try { | |
await dbClient.connect(); |
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, { useState } from "react"; | |
import Header from "./components/header"; | |
import SearchBar from "./components/SearchBar"; | |
import Home from "./components/Home"; | |
import Footer from "./components/footer"; | |
function App() { | |
const [cityName, setCityName] = useState(""); | |
//function to track change in the search bar |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.