-
-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
113 additions
and
40 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
2 changes: 2 additions & 0 deletions
2
apps/api/src/prisma/migrations/20231125221631_hidden/migration.sql
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,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "Ticket" ADD COLUMN "hidden" BOOLEAN NOT NULL DEFAULT false; |
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 |
---|---|---|
@@ -1,60 +1,64 @@ | ||
// UserContext.js | ||
import { getCookie } from 'cookies-next'; | ||
import { useRouter } from 'next/router'; | ||
import { createContext, useContext, useEffect, useState } from 'react'; | ||
import { getCookie } from "cookies-next"; | ||
import { useRouter } from "next/router"; | ||
import posthog from "posthog-js"; | ||
import { PostHogProvider } from "posthog-js/react"; | ||
import { createContext, useContext, useEffect, useState } from "react"; | ||
|
||
const UserContext = createContext(); | ||
|
||
posthog.init(process.env.NEXT_PUBLIC_POSTHOG); | ||
|
||
export const SessionProvider = ({ children }) => { | ||
const router = useRouter(); | ||
const [user, setUser] = useState(null); | ||
const [loading, setLoading] = useState(true); | ||
|
||
const fetchUserProfile = async () => { | ||
const token = getCookie('session'); | ||
const token = getCookie("session"); | ||
try { | ||
await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/v1/auth/profile`, { | ||
method: 'GET', | ||
method: "GET", | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Authorization': `Bearer ${token}` | ||
} | ||
}).then(res => res.json()) | ||
"Content-Type": "application/json", | ||
Authorization: `Bearer ${token}`, | ||
}, | ||
}) | ||
.then((res) => res.json()) | ||
.then((res) => { | ||
if(res.user){ | ||
setUser(res.user) | ||
if (res.user) { | ||
setUser(res.user); | ||
setLoading(false); | ||
} else { | ||
console.error('Failed to fetch user profile'); | ||
router.push('/auth/login'); | ||
console.error("Failed to fetch user profile"); | ||
router.push("/auth/login"); | ||
} | ||
}) | ||
}); | ||
} catch (error) { | ||
// Handle fetch errors if necessary | ||
console.error('Error fetching user profile:', error); | ||
router.push('/auth/login'); | ||
|
||
console.error("Error fetching user profile:", error); | ||
router.push("/auth/login"); | ||
} finally { | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
console.log('fetching user profile'); | ||
console.log("fetching user profile"); | ||
fetchUserProfile(); | ||
}, []); | ||
|
||
return ( | ||
<UserContext.Provider value={{ user, setUser, loading }}> | ||
{children} | ||
<PostHogProvider client={posthog}>{children}</PostHogProvider> | ||
</UserContext.Provider> | ||
); | ||
}; | ||
|
||
export const useUser = () => { | ||
const context = useContext(UserContext); | ||
if (!context) { | ||
throw new Error('useUser must be used within a UserProvider'); | ||
throw new Error("useUser must be used within a UserProvider"); | ||
} | ||
return context; | ||
}; |
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 |
---|---|---|
|
@@ -3210,6 +3210,11 @@ fastq@^1.6.0, fastq@^1.6.1: | |
dependencies: | ||
reusify "^1.0.4" | ||
|
||
fflate@^0.4.1: | ||
version "0.4.8" | ||
resolved "https://registry.yarnpkg.com/fflate/-/fflate-0.4.8.tgz#f90b82aefbd8ac174213abb338bd7ef848f0f5ae" | ||
integrity sha512-FJqqoDBR00Mdj9ppamLa/Y7vxm+PRmNWA67N846RvsoYVMKB4q3y/de5PA7gUmRMYK/8CMz2GDZQmCRN1wBcWA== | ||
|
||
filesac@^13.0.0: | ||
version "13.0.0" | ||
resolved "https://registry.yarnpkg.com/filesac/-/filesac-13.0.0.tgz#fdee2f7c477320ae99f2a5fde8f47ce7ba94b0aa" | ||
|
@@ -5222,6 +5227,13 @@ [email protected], postcss@^8.4.23, postcss@^8.4.5: | |
picocolors "^1.0.0" | ||
source-map-js "^1.0.2" | ||
|
||
posthog-js@^1.93.2: | ||
version "1.93.2" | ||
resolved "https://registry.yarnpkg.com/posthog-js/-/posthog-js-1.93.2.tgz#f3ab11983c558ad36966b552bb4ad98526cdcff6" | ||
integrity sha512-0e2kqlb4kB1/Q9poLFlMF+SUrW+DCzNBHTJuUKl177euE4LChkJipSjy2vpq98qtJ2K3Hxw7ylHf2C+dZCx4RA== | ||
dependencies: | ||
fflate "^0.4.1" | ||
|
||
posthog-node@^3.1.3: | ||
version "3.1.3" | ||
resolved "https://registry.yarnpkg.com/posthog-node/-/posthog-node-3.1.3.tgz#9c5c3dbe3360a5983a81fea2e093e5a7cdde6219" | ||
|