Skip to content

Commit

Permalink
Improve typing of user session (#1258)
Browse files Browse the repository at this point in the history
  • Loading branch information
kachar authored Dec 16, 2022
1 parent 095c7aa commit dfbcf5f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion public/locales/bg/profile.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"campaigns": "Подкрепени кампании",
"personalInfo": {
"index": "Лична информация",
"login": "Login информация:",
"login": "Данни за вход:",
"email": "Email адрес:",
"edit": "Редактирай",
"password": "Парола:",
Expand Down
2 changes: 1 addition & 1 deletion src/components/layout/nav/AdminMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default function AdminMenu() {
return null
}

const title = `${session.user.name}\n(${session.user.email})`
const title = `${session?.user?.name}\n(${session?.user?.email})`
const lettersAvatar = `${session.user?.given_name.charAt(0)}${session.user?.family_name.charAt(
0,
)}`.toUpperCase()
Expand Down
2 changes: 1 addition & 1 deletion src/components/layout/nav/PrivateMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default function PrivateMenu() {
return null
}

const title = `${session.user.name}\n(${session.user.email})`
const title = `${session?.user?.name}\n(${session?.user?.email})`
const lettersAvatar = `${session.user?.given_name.charAt(0)}${session.user?.family_name.charAt(
0,
)}`.toUpperCase()
Expand Down
15 changes: 14 additions & 1 deletion src/gql/next-auth.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import NextAuth from 'next-auth'
import { ServerUser } from 'service/auth'

/**
* Declaring the Session and User type as per docs here:
Expand Down Expand Up @@ -28,3 +28,16 @@ declare module 'next-auth' {
picture: string
}
}

declare module 'next-auth/jwt' {
/**
* JWT contents which builds the session object
*/
export interface JWT {
accessToken: string
accessTokenExpires: number
refreshToken: string
user: ServerUser | null
expires?: number
}
}
13 changes: 0 additions & 13 deletions src/pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,6 @@ import {
import { apiClient } from 'service/apiClient'
import { endpoints } from 'service/apiEndpoints'

declare module 'next-auth/jwt' {
/**
* JWT contents which builds the session object
*/
export interface JWT {
accessToken: string
accessTokenExpires: number
refreshToken: string
user: ServerUser | null
expires?: number
}
}

const onCreate: EventCallbacks['createUser'] = async ({ user }) => {
const { email } = user

Expand Down

0 comments on commit dfbcf5f

Please sign in to comment.