-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚀 Handle user creation and login in Google strategy
- Loading branch information
Showing
11 changed files
with
285 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
REACT_APP_RAPID_API_URL=https://judge0-ce.p.rapidapi.com/submissions | ||
REACT_APP_RAPID_API_HOST=judge0-ce.p.rapidapi.com | ||
REACT_APP_RAPID_API_KEY=0e58c401femsh4bc6914c8b658f0p1108a6jsn88ac8d898095 | ||
|
||
NODE_ENV=development | ||
NEXT_PUBLIC_DEV_API_URL=http://localhost:8000 | ||
NEXT_PUBLIC_PROD_API_URL=https://wanderer.vercel.app |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use client' | ||
|
||
import { useState } from 'react' | ||
import { QueryClient, QueryClientProvider } from 'react-query' | ||
import { ReactQueryDevtools } from "react-query/devtools"; | ||
|
||
|
||
export const ReactQueryClientProvider = ({ children }: { children: React.ReactNode }) => { | ||
const [queryClient] = useState( | ||
() => | ||
new QueryClient({ | ||
defaultOptions: { | ||
queries: { | ||
staleTime: 60 * 1000, | ||
}, | ||
}, | ||
}) | ||
) | ||
return <QueryClientProvider client={queryClient}>{children} <ReactQueryDevtools initialIsOpen={false}/></QueryClientProvider> | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
"use client" | ||
import { createContext, useContext , useState, useEffect} from "react"; | ||
import { ManagerOptions, Socket, SocketOptions, io } from "socket.io-client"; | ||
import { UserContext } from "./userContext"; | ||
|
||
|
||
type SocketContextProps = { | ||
children: React.ReactNode | ||
} | ||
|
||
|
||
type SocketContext = { | ||
socket: Socket | null, | ||
|
||
} | ||
|
||
|
||
export const SocketContext = createContext<SocketContext>({} as SocketContext); | ||
|
||
|
||
export const SocketContextProvider = ({ children }: SocketContextProps) => { | ||
const socketOptions: Partial<ManagerOptions & SocketOptions> = { | ||
autoConnect: false, | ||
reconnectionAttempts: 3, | ||
withCredentials: true, | ||
transports: ["polling"] | ||
} | ||
|
||
|
||
const {user, isUserLoading} = useContext(UserContext) | ||
const [socket, setSocket] = useState<Socket | null>(null); | ||
const [connected, setConnected] = useState(false); | ||
const [reconnecting, setReconnecting] = useState(false); | ||
|
||
useEffect(() => { | ||
if (user && !isUserLoading) { | ||
const newSocket = io(process.env.NEXT_PUBLIC_BACKEND_URL as string, socketOptions); | ||
setSocket(newSocket); | ||
} | ||
}, [user, isUserLoading]); | ||
|
||
|
||
useEffect(() => { | ||
if (socket) { | ||
socket.on("connect", () => { | ||
setConnected(true); | ||
setReconnecting(false); | ||
}); | ||
socket.on("reconnect", () => { | ||
setReconnecting(true); | ||
}); | ||
socket.on("reconnect_error", () => { | ||
setReconnecting(false); | ||
}); | ||
socket.on("reconnect_failed", () => { | ||
setReconnecting(false); | ||
}); | ||
} | ||
}, [socket]); | ||
|
||
return ( | ||
<SocketContext.Provider value={{ socket }}> | ||
{children} | ||
</SocketContext.Provider> | ||
) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"use client" | ||
|
||
import { useQuery } from "react-query"; | ||
import { createContext } from "react"; | ||
import { api } from "@/lib/api"; | ||
|
||
|
||
type ContextProps = { | ||
children: React.ReactNode | ||
} | ||
|
||
|
||
type UserContext = { | ||
user: User, | ||
isUserLoading: boolean | ||
} | ||
|
||
|
||
export const UserContext = createContext<UserContext>({} as UserContext) | ||
|
||
|
||
const UserContextProvider = ({ children }: ContextProps) => { | ||
const getUser = async () => { | ||
const response = await api.get('/user') | ||
return response.data | ||
} | ||
const { data: user, isLoading: isUserLoading } = useQuery('user', getUser, { | ||
refetchOnWindowFocus: true, | ||
staleTime: 1000 * 60 * 5, | ||
|
||
}) | ||
|
||
|
||
return ( | ||
<UserContext.Provider value={{ user, isUserLoading }}> | ||
{children} | ||
</UserContext.Provider> | ||
) | ||
} | ||
|
||
|
||
export default UserContextProvider; | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import axios from "axios"; | ||
|
||
export const api = axios.create({ | ||
baseURL: process.env.NODE_ENV === "production" ? process.env.NEXT_PUBLIC_PROD_API_URL : process.env.NEXT_PUBLIC_DEV_API_URL, | ||
withCredentials: true, | ||
}) |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
type User = { | ||
userId: string, | ||
email: string, | ||
firstName: string, | ||
lastName: string, | ||
role: string, | ||
avatarUrl: string, | ||
bio: string, | ||
mfaEnabled: boolean, | ||
verified: boolean, | ||
phoneNumber: string | ||
|
||
} | ||
|
||
|
||
type PracticeSession = { | ||
sessionId: string, | ||
userId: string, | ||
problemId: string, | ||
createdAt: Date, | ||
|
||
} | ||
|
||
|
||
type Problem = { | ||
problemId: string, | ||
description: string, | ||
difficulty: string, | ||
title: string, | ||
tags: string[], | ||
examples: string[], | ||
hints: string[], | ||
|
||
} |