From e957ce1df4e72eb48c75059a2e00d700c7e76285 Mon Sep 17 00:00:00 2001 From: Ilko Kacharov Date: Fri, 16 Dec 2022 10:59:34 +0200 Subject: [PATCH] Improve typing of user session --- public/locales/bg/profile.json | 2 +- src/components/layout/nav/AdminMenu.tsx | 2 +- src/components/layout/nav/PrivateMenu.tsx | 2 +- src/gql/next-auth.d.ts | 15 ++++++++++++++- src/pages/api/auth/[...nextauth].ts | 13 ------------- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/public/locales/bg/profile.json b/public/locales/bg/profile.json index 7c9ccca82..7ba18823f 100644 --- a/public/locales/bg/profile.json +++ b/public/locales/bg/profile.json @@ -3,7 +3,7 @@ "campaigns": "Подкрепени кампании", "personalInfo": { "index": "Лична информация", - "login": "Login информация:", + "login": "Данни за вход:", "email": "Email адрес:", "edit": "Редактирай", "password": "Парола:", diff --git a/src/components/layout/nav/AdminMenu.tsx b/src/components/layout/nav/AdminMenu.tsx index dc3adfe42..794e26f4b 100644 --- a/src/components/layout/nav/AdminMenu.tsx +++ b/src/components/layout/nav/AdminMenu.tsx @@ -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() diff --git a/src/components/layout/nav/PrivateMenu.tsx b/src/components/layout/nav/PrivateMenu.tsx index 52b258e84..86fa6dbbd 100644 --- a/src/components/layout/nav/PrivateMenu.tsx +++ b/src/components/layout/nav/PrivateMenu.tsx @@ -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() diff --git a/src/gql/next-auth.d.ts b/src/gql/next-auth.d.ts index 1d82533a2..fae7daf01 100644 --- a/src/gql/next-auth.d.ts +++ b/src/gql/next-auth.d.ts @@ -1,4 +1,4 @@ -import NextAuth from 'next-auth' +import { ServerUser } from 'service/auth' /** * Declaring the Session and User type as per docs here: @@ -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 + } +} diff --git a/src/pages/api/auth/[...nextauth].ts b/src/pages/api/auth/[...nextauth].ts index d99662aa6..27f8177c5 100644 --- a/src/pages/api/auth/[...nextauth].ts +++ b/src/pages/api/auth/[...nextauth].ts @@ -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