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 _mongoose, { connect } from "mongoose"; | |
declare global { | |
var mongoose: { | |
promise: ReturnType<typeof connect> | null; | |
conn: typeof _mongoose | null; | |
}; | |
} | |
const MONGODB_URI = process.env.MONGODB_URI; |
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
<button | |
onClick={toggleTheme} | |
className="p-2 rounded-full hover:bg-gray-200 dark:hover:bg-gray-700 focus:outline-none" | |
aria-label="Toggle theme" | |
> | |
{theme === 'light' ? ( | |
<Moon className="h-5 w-5 text-gray-700 dark:text-gray-300" /> | |
) : ( | |
<Sun className="h-5 w-5 text-gray-700 dark:text-gray-300" /> | |
)} |
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 * as React from "react"; | |
import clsx from "clsx"; | |
export default function ToggleMessage() { | |
const [visible, setVisible] = React.useState(false); | |
const toggleVisibility = () => { | |
setVisible(!visible); | |
}; |
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 from 'react'; | |
import { BrowserRouter, Routes, Route } from 'react-router-dom'; | |
import { AuthProvider } from './components/AuthProvider'; | |
import { ProtectedRoute } from './components/ProtectedRoute'; | |
import { Login } from './components/Login'; | |
import { Signup } from './components/Signup'; | |
import { Dashboard } from './components/Dashboard'; | |
function App() { | |
return ( |
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 Realm from 'realm'; | |
import { RealmApp } from './app'; | |
const appConfig = { | |
id: 'your-app-id', | |
timeout: 10000, | |
}; | |
const app = new RealmApp(appConfig); |
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, useContext } from 'react'; | |
import { AuthContext } from './AuthProvider'; | |
import { useNavigate } from 'react-router-dom'; | |
const Signup = () => { | |
const [email, setEmail] = useState(''); | |
const [password, setPassword] = useState(''); | |
const [confirmPassword, setConfirmPassword] = useState(''); | |
const [error, setError] = useState(null); | |
const { signup } = useContext(AuthContext); |
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, { useContext } from 'react'; | |
import { AuthContext } from './AuthProvider'; | |
import { Navigate } from 'react-router-dom'; | |
const ProtectedRoute = ({ children }) => { | |
const { user, loading } = useContext(AuthContext); | |
if (loading) { | |
return <div>Loading...</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 React, { useState, useContext } from 'react'; | |
import { AuthContext } from './AuthProvider'; | |
import { useNavigate } from 'react-router-dom'; | |
const Login = () => { | |
const [email, setEmail] = useState(''); | |
const [password, setPassword] = useState(''); | |
const [error, setError] = useState(null); | |
const { login } = useContext(AuthContext); | |
const navigate = useNavigate(); |
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, { createContext, useState, useEffect } from 'react'; | |
import { useRealmApp } from './realm'; | |
import { useNavigate } from 'react-router-dom'; | |
const AuthContext = createContext(); | |
const AuthProvider = ({ children }) => { | |
const app = useRealmApp(); | |
const navigate = useNavigate(); | |
const [user, setUser] = useState(app.currentUser); |
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'; | |
const uri = 'mongodb+srv://weezy:[email protected]/?retryWrites=true&w=majority'; | |
const client = new MongoClient(uri); | |
async function handler(req, res) { | |
if (req.method === 'GET') { | |
try { | |
await client.connect(); | |
const database = client.db('kittens'); | |
const collection = database.collection('kittens'); |
NewerOlder