From 98707e66e112a4f0bef5e89f33bcf8e047f1d3c9 Mon Sep 17 00:00:00 2001 From: Ansari Date: Thu, 13 Jul 2023 17:51:28 +0530 Subject: [PATCH] fix: Refresh session (#10019) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Refresh session 🔄 * Update apps/web/components/ui/UsernameAvailability/PremiumTextfield.tsx Co-authored-by: Omar López * Update apps/web/components/ui/UsernameAvailability/UsernameTextfield.tsx Co-authored-by: Omar López * Update packages/features/auth/lib/next-auth-options.ts Co-authored-by: Omar López --------- Co-authored-by: Ansari Co-authored-by: Shivam Kalra Co-authored-by: Omar López --- .../components/ui/UsernameAvailability/PremiumTextfield.tsx | 3 +++ .../components/ui/UsernameAvailability/UsernameTextfield.tsx | 3 +++ apps/web/package.json | 2 +- packages/features/auth/lib/next-auth-options.ts | 2 +- packages/features/auth/package.json | 2 +- 5 files changed, 9 insertions(+), 3 deletions(-) diff --git a/apps/web/components/ui/UsernameAvailability/PremiumTextfield.tsx b/apps/web/components/ui/UsernameAvailability/PremiumTextfield.tsx index 950da96920..27182e2b5c 100644 --- a/apps/web/components/ui/UsernameAvailability/PremiumTextfield.tsx +++ b/apps/web/components/ui/UsernameAvailability/PremiumTextfield.tsx @@ -1,5 +1,6 @@ import classNames from "classnames"; import { debounce, noop } from "lodash"; +import { useSession } from "next-auth/react"; import { useRouter } from "next/router"; import type { RefCallback } from "react"; import { useEffect, useMemo, useState } from "react"; @@ -46,6 +47,7 @@ const obtainNewUsernameChangeCondition = ({ const PremiumTextfield = (props: ICustomUsernameProps) => { const { t } = useLocale(); + const { data: session, update } = useSession(); const { currentUsername, setCurrentUsername = noop, @@ -94,6 +96,7 @@ const PremiumTextfield = (props: ICustomUsernameProps) => { const updateUsername = trpc.viewer.updateProfile.useMutation({ onSuccess: async () => { onSuccessMutation && (await onSuccessMutation()); + await update(); setOpenDialogSaveUsername(false); }, onError: (error) => { diff --git a/apps/web/components/ui/UsernameAvailability/UsernameTextfield.tsx b/apps/web/components/ui/UsernameAvailability/UsernameTextfield.tsx index 05871030c7..dd0c3d8456 100644 --- a/apps/web/components/ui/UsernameAvailability/UsernameTextfield.tsx +++ b/apps/web/components/ui/UsernameAvailability/UsernameTextfield.tsx @@ -1,5 +1,6 @@ import classNames from "classnames"; import { debounce, noop } from "lodash"; +import { useSession } from "next-auth/react"; import type { RefCallback } from "react"; import { useEffect, useMemo, useState } from "react"; @@ -23,6 +24,7 @@ interface ICustomUsernameProps { const UsernameTextfield = (props: ICustomUsernameProps & Partial>) => { const { t } = useLocale(); + const { data: session, update } = useSession(); const { currentUsername, setCurrentUsername = noop, @@ -69,6 +71,7 @@ const UsernameTextfield = (props: ICustomUsernameProps & Partial { onErrorMutation && onErrorMutation(error); diff --git a/apps/web/package.json b/apps/web/package.json index 6817237671..e46a2199e7 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -89,7 +89,7 @@ "micro": "^10.0.1", "mime-types": "^2.1.35", "next": "^13.4.6", - "next-auth": "^4.20.1", + "next-auth": "^4.22.1", "next-axiom": "^0.17.0", "next-collect": "^0.2.1", "next-i18next": "^13.2.2", diff --git a/packages/features/auth/lib/next-auth-options.ts b/packages/features/auth/lib/next-auth-options.ts index 00b6ac5333..4a496fd7a9 100644 --- a/packages/features/auth/lib/next-auth-options.ts +++ b/packages/features/auth/lib/next-auth-options.ts @@ -349,7 +349,7 @@ export const AUTH_OPTIONS: AuthOptions = { }, providers, callbacks: { - async jwt({ token, user, account }) { + async jwt({ token, user, account, trigger, session }) { const autoMergeIdentities = async () => { const existingUser = await prisma.user.findFirst({ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion diff --git a/packages/features/auth/package.json b/packages/features/auth/package.json index 5948ed54b8..9f451d5709 100644 --- a/packages/features/auth/package.json +++ b/packages/features/auth/package.json @@ -16,7 +16,7 @@ "handlebars": "^4.7.7", "jose": "^4.13.1", "lru-cache": "^9.0.3", - "next-auth": "^4.20.1", + "next-auth": "^4.22.1", "nodemailer": "^6.7.8", "otplib": "^12.0.1" }