Skip to content

Commit c040926

Browse files
committed
feat: enhance NextAuth types and update configuration for improved role management
correct types error eliminate duplicate next-auth.d.ts files
1 parent 86c5a49 commit c040926

File tree

8 files changed

+2020
-1670
lines changed

8 files changed

+2020
-1670
lines changed

apps/admin-portal/src/app/types/next-auth.d.ts renamed to apps/admin-portal/next-auth-types.d.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
declare module 'next-auth' {
1+
// types/next-auth.d.ts
2+
import { DefaultSession } from "next-auth";
3+
4+
declare module "next-auth" {
25
interface Session {
36
user: {
47
roles?: string[];
58
id: string;
69
name?: string | null;
710
email?: string | null;
811
image?: string | null;
9-
};
12+
} & DefaultSession["user"];
1013
}
11-
1214
interface User {
13-
login?: string;
15+
roles?: string[];
1416
}
1517
}
16-
17-
declare module '@auth/core/jwt' {
18+
declare module "next-auth/jwt" {
1819
interface JWT {
1920
roles?: string[];
2021
accessToken?: string;

apps/admin-portal/next-auth.d.ts

Lines changed: 0 additions & 35 deletions
This file was deleted.

apps/admin-portal/src/app/components/docusaurus-navbar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,9 @@ export function DocusaurusNavbar({ siteKey }: DocusaurusNavbarProps): React.JSX.
179179
<div className="docusaurus-navbar__user-email">
180180
{session.user.email}
181181
</div>
182-
{session.user.roles && session.user.roles.length > 0 && (
182+
{session.user.roles && session.user.roles.length > 0 && (
183183
<div className="docusaurus-navbar__user-roles">
184-
{session.user.roles.join(', ')}
184+
{session.user.roles.join(', ')}
185185
</div>
186186
)}
187187
</div>

apps/admin-portal/src/app/lib/auth.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import NextAuth from "next-auth"
2-
import GitHub from "next-auth/providers/github"
1+
import NextAuth from "next-auth";
2+
import GitHub from "next-auth/providers/github";
33

44
export const { handlers, auth, signIn, signOut } = NextAuth({
55
debug: process.env.NODE_ENV === "development",
@@ -105,7 +105,8 @@ export const { handlers, auth, signIn, signOut } = NextAuth({
105105
return token;
106106
},
107107
async session({ session, token }: any) {
108-
if (token.roles && session.user) {
108+
if (session.user) {
109+
session.user.id = token.sub;
109110
session.user.roles = token.roles as string[];
110111
}
111112
return session;

apps/admin-portal/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"../../apps/admin-portal/.next/types/**/*.ts",
3636
"../../dist/apps/admin-portal/.next/types/**/*.ts",
3737
"next-env.d.ts",
38+
"next-auth-types.d.ts",
3839
".next/types/**/*.ts"
3940
],
4041
"exclude": [

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@
361361
"jsonc-eslint-parser": "^2.1.0",
362362
"lint-staged": "^16.1.2",
363363
"npm-run-all": "^4.1.5",
364-
"nx": "21.2.1",
364+
"nx": "21.2.2",
365365
"nx-cloud": "^19.1.0",
366366
"playwright": "^1.52.0",
367367
"postcss": "^8.5.5",

pnpm-lock.yaml

Lines changed: 2002 additions & 1622 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@
5252
"**/*.ts",
5353
"**/*.tsx",
5454
"*.d.ts",
55-
"plugins"
55+
"plugins",
56+
"types/**/*.d.ts",
57+
"src/**/*"
5658
],
5759
"exclude": [
5860
"node_modules",

0 commit comments

Comments
 (0)