Skip to content

Connect, collaborate, and grow with a community of TypeScript developers

Use login for the user (#100)

Sean Boult4f7e111b54e2
diff --git a/package.json b/package.json
index 90af1210..25c12cad 100644
--- a/package.json
+++ b/package.json
@@ -80,14 +80,14 @@
"autoprefixer": "^10.4.14",
"eslint": "^8.40.0",
"eslint-config-next": "^13.4.2",
+ "husky": "^8.0.0",
"monaco-editor": "=0.36.1",
"postcss": "^8.4.21",
"prettier": "^2.8.8",
"prettier-plugin-tailwindcss": "^0.2.8",
"prisma": "^4.14.0",
"tailwindcss": "^3.3.0",
- "tsx": "^3.12.7",
- "husky": "^8.0.0"
+ "tsx": "^3.12.7"
},
"ct3aMetadata": {
"initVersion": "7.13.1"
@@ -95,5 +95,10 @@
"prisma": {
"schema": "./prisma/schema.prisma",
"seed": "npx tsx ./prisma/seed.ts"
+ },
+ "pnpm": {
+ "patchedDependencies": {
+ }
}
}
diff --git a/patches/[email protected] b/patches/[email protected]
new file mode 100644
index 00000000..a098b4a1
--- /dev/null
+++ b/patches/[email protected]
@@ -0,0 +1,51 @@
+diff --git a/package.json b/package.json
+index 32b6844c5342b3a577fc090be305d2d3584c4998..1366e857838c134a36dfaf88a908aae3968cccdb 100644
+--- a/package.json
++++ b/package.json
+@@ -82,6 +82,7 @@
+ "@babel/preset-react": "^7.17.12",
+ "@babel/preset-typescript": "^7.17.12",
+ "@edge-runtime/jest-environment": "1.1.0-beta.35",
++ "@next-auth/tsconfig": "0.0.0",
+ "@swc/core": "^1.2.198",
+ "@swc/jest": "^0.2.21",
+ "@testing-library/dom": "^8.13.0",
+@@ -110,8 +111,7 @@
+ "postcss-nested": "^5.0.6",
+ "react": "^18",
+ "react-dom": "^18",
+- "whatwg-fetch": "^3.6.2",
+- "@next-auth/tsconfig": "0.0.0"
++ "whatwg-fetch": "^3.6.2"
+ },
+ "scripts": {
+ "build": "pnpm clean && pnpm build:js && pnpm build:css",
+@@ -124,5 +124,10 @@
+ "test": "jest --config ./config/jest.config.js",
+ "generate-providers": "node ./config/generate-providers.js",
+ "lint": "eslint src config tests"
++ },
++ "pnpm": {
++ "patchedDependencies": {
++ }
+ }
+ }
+\ No newline at end of file
+diff --git a/providers/github.js b/providers/github.js
+index d9a68e0f126df7b05fb4b38fa2969827765c43c6..c5c1af28e1773561ea018a4d4720b7e55c632066 100644
+--- a/providers/github.js
++++ b/providers/github.js
+@@ -47,11 +47,9 @@ function Github(options) {
+ },
+
+ profile(profile) {
+- var _profile$name;
+-
+ return {
+ id: profile.id.toString(),
+- name: (_profile$name = profile.name) !== null && _profile$name !== void 0 ? _profile$name : profile.login,
++ name: profile.login,
+ email: profile.email,
+ image: profile.avatar_url
+ };
\ No newline at end of file
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 8ff1c142..6601ea60 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -1,5 +1,14 @@
lockfileVersion: '6.1'
+settings:
+ autoInstallPeers: true
+ excludeLinksFromLockfile: false
+
+patchedDependencies:
+ hash: z7hogwjmsy5ijambzc6ekvh27q
+ path: patches/[email protected]
+
dependencies:
'@clerk/nextjs':
specifier: ^4.19.0
@@ -102,7 +111,7 @@ dependencies:
next-auth:
specifier: ^4.22.1
+ version: 4.22.1(patch_hash=z7hogwjmsy5ijambzc6ekvh27q)([email protected])([email protected])([email protected])
next-themes:
specifier: ^0.2.1
@@ -675,7 +684,7 @@ packages:
next-auth: ^4
dependencies:
'@prisma/client': 4.14.0([email protected])
+ next-auth: 4.22.1(patch_hash=z7hogwjmsy5ijambzc6ekvh27q)([email protected])([email protected])([email protected])
dev: false
@@ -4679,7 +4688,7 @@ packages:
resolution: {integrity: sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==}
dev: true
+ /[email protected](patch_hash=z7hogwjmsy5ijambzc6ekvh27q)([email protected])([email protected])([email protected]):
resolution: {integrity: sha512-NTR3f6W7/AWXKw8GSsgSyQcDW6jkslZLH8AiZa5PQ09w1kR8uHtR9rez/E9gAq/o17+p0JYHE8QjF3RoniiObA==}
peerDependencies:
next: ^12.2.5 || ^13
@@ -4703,6 +4712,7 @@ packages:
react-dom: 18.2.0([email protected])
uuid: 8.3.2
dev: false
+ patched: true
resolution: {integrity: sha512-B+AKNfYNIzh0vqQQKqQItTS8evEouKD7H5Hj3kmuPERwddR2TxvDSFZuTj6T7Jfn1oyeUyJMydPl1Bkxkh0W7A==}
@@ -6312,7 +6322,3 @@ packages:
resolution: {integrity: sha512-bXE4cR/kVZhKZX/RjPEflHaKVhUVl85noU3v6b8apfQEc1x4A+zBxjZ4lN8LqGd6WZ3dl98pY4o717VFmoPp+A==}
dev: false
-
-settings:
- autoInstallPeers: true
- excludeLinksFromLockfile: false
diff --git a/src/components/ui/navigation.tsx b/src/components/ui/navigation.tsx
index 1b538afd..51c6bfcf 100644
--- a/src/components/ui/navigation.tsx
+++ b/src/components/ui/navigation.tsx
@@ -3,7 +3,7 @@
import { useTheme } from 'next-themes';
import Link from 'next/link';
-import { LogIn, User, Bell, Moon, Sun, Loader2 } from 'lucide-react';
+import { LogIn, Plus, Settings, User, Bell, Moon, Sun, Loader2 } from 'lucide-react';
import { useEffect, useState } from 'react';
import { useRouter, usePathname } from 'next/navigation';
import { signIn, signOut } from 'next-auth/react';
@@ -26,6 +26,7 @@ import {
DropdownMenuTrigger,
} from './dropdown-menu';
import { useSession } from 'next-auth/react';
+import { RoleTypes } from '@prisma/client';
export function Navigation() {
const [mounted, setMounted] = useState(false);
@@ -35,6 +36,10 @@ export function Navigation() {
const router = useRouter();
const pathname = usePathname();
+ const isAdmin = session?.user?.role?.includes(RoleTypes.ADMIN);
+ const isMod = session?.user?.role?.includes(RoleTypes.MODERATOR);
+ const isAdminOrMod = isAdmin || isMod;
+
// NOTE: 1. loading == true -> 2. signIn() -> 3. session status == 'loading' (loading == false)
const handleSignIn = async () => {
try {
@@ -148,16 +153,26 @@ export function Navigation() {
</button>
</DropdownMenuTrigger>
<DropdownMenuContent className="w-56">
- <DropdownMenuLabel className="text-neutral-600 dark:text-neutral-400">
- My Account
- </DropdownMenuLabel>
- <DropdownMenuSeparator />
+ <Link className="block" href="/create">
+ <DropdownMenuItem className="rounded-lg p-2 duration-300 focus:bg-accent focus:outline-none">
+ <Plus className="mr-2 h-4 w-4" />
+ <span>Create a Challange</span>
+ </DropdownMenuItem>
+ </Link>
<Link className="block" href={`/@${session.user.name ?? ''}`}>
<DropdownMenuItem className="rounded-lg p-2 duration-300 focus:bg-accent focus:outline-none">
<User className="mr-2 h-4 w-4" />
<span>Profile</span>
</DropdownMenuItem>
</Link>
+ {isAdminOrMod && (
+ <Link className="block" href="/admin">
+ <DropdownMenuItem className="rounded-lg p-2 duration-300 focus:bg-accent focus:outline-none">
+ <Settings className="mr-2 h-4 w-4" />
+ <span>Admin</span>
+ </DropdownMenuItem>
+ </Link>
+ )}
<DropdownMenuSeparator />
<DropdownMenuItem onClick={() => void handleSignOut()}>
<span>Log out</span>
diff --git a/src/server/auth.ts b/src/server/auth.ts
index 54e4f4c1..1a03e75e 100644
--- a/src/server/auth.ts
+++ b/src/server/auth.ts
@@ -2,7 +2,7 @@ import { PrismaAdapter } from '@next-auth/prisma-adapter';
import type { Role, RoleTypes } from '@prisma/client';
import { type GetServerSidePropsContext } from 'next';
import { getServerSession, type DefaultSession, type NextAuthOptions } from 'next-auth';
-import GitHubProvider from 'next-auth/providers/github';
+import GitHubProvider, { GithubProfile } from 'next-auth/providers/github';
import { env } from '~/env.mjs';
import { prisma } from '~/server/db';