Skip to content

Instantly share code, notes, and snippets.

View user.js
import useSWR from 'swr';
import { fetcher } from '@/actions';
import { useEffect, useState } from "react"
function doesHttpOnlyCookieExist(cookiename) {
var d = new Date();
d.setTime(d.getTime() + (1000));
var expires = "expires=" + d.toUTCString();
document.cookie = cookiename + "=new_value;path=/;" + expires;
View LoginForm.jsx
import React, { useState } from 'react';
import { useForm } from 'react-hook-form';
import { fetchChats } from '../actions/Logina';
import { useDispatch } from 'react-redux';
import firebase from 'firebase/app';
import "firebase/database"
import db from '../db/firestore';
import "firebase/messaging";
View index.ts
import type { InferGetStaticPropsType } from "next"
import { getAllProducts } from "@framework/product"
import { getConfig } from "@framework/api/config"
import { Layout } from "@components/common"
import { ProductCard } from "@components/product"
import { Grid, Hero, Marquee } from "@components/ui"
export async function getStaticProps() {
const config = getConfig()
View [id].js
import Car from '../../../models/Carb'
import connectDb from '../../../utils/connectDb';
export default async (req, res) => {
await connectDb();
const { id } = req.query
const car = await Car.findById(id);
res.status(200).json(car);
};
View [id].js
import { Container, Jumbotron } from "reactstrap";
import axios from "axios";
function CarPage({car: { name, model, description, pdate, sdate,pprice, sprice, profit }}){
return(
<>
<Container>
<Jumbotron>
View admin.ts
import { deleteFile } from "../util/file";
import { validationResult } from "express-validator";
import { Product, ProductDoc } from "../database/models";
import { Request, Response, NextFunction } from "express";
import { InternalServerError, NotFoundError } from "../errors";
import { Cloudinary } from "../services/cloudinary";
const path = require('path');
const DatauriParser = require('datauri/parser');
const parser = new DatauriParser();
View index.js
import Link from 'next/link'
import {useGetData} from 'actions'
import { withPageAuthRequired } from '@auth0/nextjs-auth0';
import { useRouter } from "next/router"
import { useEffect } from 'react';
export default function portfolios({user}){
const router = useRouter();
useEffect(() => {
View auth0.js
export const isAuthorized = (user, role) => {
return user && user[process.env.AUTH0_NAMESPACE + '/roles'].includes(role);
};
export const authorizeUser = async (req, res) => {
const session = await auth0.getSession(req, res);
if (!session || !session.user) {
res.writeHead(302, {
Location: '/api/auth/login',
});
View new.js
import withApollo from '../../hoc/withApollo';
import withAuth from '../../hoc/withAuth';
import PortfolioForm from '../../components/forms/PortfolioForm';
import { useCreatePortfolio } from '../../apolloLogic/actions';
import { useRouter } from 'next/router';
import BaseLayout from '@/layouts/BaseLayout';
const PortfolioCreate = () => {
const [createPortfolio, { error }] = useCreatePortfolio();
const router = useRouter();