-
-
Notifications
You must be signed in to change notification settings - Fork 536
refactor: simplify session casting and improve type safety in MyMento… #3505
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,13 +8,13 @@ export type ExtendedProfile = { | |||||||||||||||||||||
| export type ExtendedSession = Session & { | ||||||||||||||||||||||
| accessToken?: string | ||||||||||||||||||||||
| user?: Session['user'] & { | ||||||||||||||||||||||
| email?: string | ||||||||||||||||||||||
| expires?: string | ||||||||||||||||||||||
| image?: string | ||||||||||||||||||||||
| isLeader?: boolean | ||||||||||||||||||||||
|
Comment on lines
10
to
14
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: cat -n frontend/src/types/auth.tsRepository: OWASP/Nest Length of output: 576 🌐 Web query:
💡 Result: In next-auth v4.24.x (including v4.24.13), the default TypeScript types already define the session’s user as having (optional)
Create a declaration file (e.g. import NextAuth, { DefaultSession } from "next-auth"
declare module "next-auth" {
interface Session {
user: {
// your custom fields here, e.g. id: string
} & DefaultSession["user"] // keeps name/email/image types
}
}This ensures Sources: 🏁 Script executed: rg "session\.user\.email|session\.user\.image" --type ts --type tsx -A 2 -B 2Repository: OWASP/Nest Length of output: 81 🏁 Script executed: rg "ExtendedSession" --type ts --type tsx -A 3 | head -100Repository: OWASP/Nest Length of output: 81 🏁 Script executed: rg "session\.user\.email|session\.user\.image" -A 2 -B 2Repository: OWASP/Nest Length of output: 36 🏁 Script executed: rg "ExtendedSession" -A 3 | head -150Repository: OWASP/Nest Length of output: 10757 🏁 Script executed: fd "\.(ts|tsx)$" frontend/src --type f | head -20Repository: OWASP/Nest Length of output: 933 🏁 Script executed: rg "email" frontend/src --type-add 'ts:*.{ts,tsx}' -t ts | grep -i "session\|user\|email" | head -40Repository: OWASP/Nest Length of output: 20371 🏁 Script executed: rg "\.image" frontend/src --type-add 'ts:*.{ts,tsx}' -t ts | head -40Repository: OWASP/Nest Length of output: 320 🏁 Script executed: cat frontend/src/components/UserMenu.tsx | head -80Repository: OWASP/Nest Length of output: 2804 🏁 Script executed: rg "session\.user\." frontend/src/components/UserMenu.tsx -B 2 -A 2Repository: OWASP/Nest Length of output: 36 Avoid narrowing In next-auth v4.24.13, 🛠️ Proposed fix user?: Session['user'] & {
- email?: string
+ email?: Session['user']['email']
expires?: string
- image?: string
+ image?: Session['user']['image']
isLeader?: boolean📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||
| isMentor?: boolean | ||||||||||||||||||||||
| isOwaspStaff?: boolean | ||||||||||||||||||||||
| login?: string | ||||||||||||||||||||||
| name?: string | ||||||||||||||||||||||
| email?: string | ||||||||||||||||||||||
| image?: string | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: OWASP/Nest
Length of output: 228
🏁 Script executed:
Repository: OWASP/Nest
Length of output: 4325
🏁 Script executed:
Repository: OWASP/Nest
Length of output: 397
🏁 Script executed:
Repository: OWASP/Nest
Length of output: 146
Fix unauthenticated user handling with proper session status check.
Currently, the loading gate
!userNamecannot distinguish between the loading state (session data still loading) and the unauthenticated state (user not logged in). Since there's no middleware or layout-level route protection for/my/*routes, an unauthenticated user will see the spinner indefinitely.Verify the session loading state by including
statusfromuseSession():Then handle all three states explicitly:
loading,unauthenticated, andauthenticated. For the unauthenticated case, redirect to login or show an appropriate message instead of displaying the spinner.🤖 Prompt for AI Agents