From dc3f6625087f2143c4ab6ef436787ec1c3b32d72 Mon Sep 17 00:00:00 2001 From: Bart Tadych Date: Thu, 5 Jan 2023 18:02:23 +0100 Subject: [PATCH] feat: added payload parameter to MoralisNextAuthProvider. (#946) --- .changeset/soft-bananas-applaud.md | 5 +++++ .../modules/Authentication/Authentication.tsx | 3 ++- .../app/components/modules/Profile/Profile.tsx | 1 + packages/next/src/auth/MoralisNextAuthProvider.ts | 14 ++++++++++++-- 4 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 .changeset/soft-bananas-applaud.md diff --git a/.changeset/soft-bananas-applaud.md b/.changeset/soft-bananas-applaud.md new file mode 100644 index 0000000000..1c54411863 --- /dev/null +++ b/.changeset/soft-bananas-applaud.md @@ -0,0 +1,5 @@ +--- +'@moralisweb3/next': patch +--- + +Added a new parameter to the `MoralisNextAuthProvider` class: `payload`. It allows to keep some extra information in the session. diff --git a/demos/nextjs/app/components/modules/Authentication/Authentication.tsx b/demos/nextjs/app/components/modules/Authentication/Authentication.tsx index df4772b223..740ad17580 100644 --- a/demos/nextjs/app/components/modules/Authentication/Authentication.tsx +++ b/demos/nextjs/app/components/modules/Authentication/Authentication.tsx @@ -62,7 +62,8 @@ const Authentication = () => { } const signature = await signMessageAsync({ message: challenge.message }); - await signIn('moralis-auth', { message: challenge.message, signature, redirect: false }); + const payload = `Authentication time: ${Date.now()}`; + await signIn('moralis-auth', { message: challenge.message, signature, payload, redirect: false }); // redirects to main page push('/'); diff --git a/demos/nextjs/app/components/modules/Profile/Profile.tsx b/demos/nextjs/app/components/modules/Profile/Profile.tsx index c98c3b6e3c..a37ef83f45 100644 --- a/demos/nextjs/app/components/modules/Profile/Profile.tsx +++ b/demos/nextjs/app/components/modules/Profile/Profile.tsx @@ -12,6 +12,7 @@ const Profile: FC = () => { profile

{data?.user?.address}

Profile ID: {data?.user.profileId}

+

Payload: {data?.user.payload}

Native Balance: {balance?.balance.ether} Ether

); diff --git a/packages/next/src/auth/MoralisNextAuthProvider.ts b/packages/next/src/auth/MoralisNextAuthProvider.ts index 80501bd643..4ac7a76513 100644 --- a/packages/next/src/auth/MoralisNextAuthProvider.ts +++ b/packages/next/src/auth/MoralisNextAuthProvider.ts @@ -33,20 +33,30 @@ const MoralisNextAuthProvider = () => type: 'text', placeholder: 'Evm', }, + /** + * Some extra information keeping in a session. + */ + payload: { + label: 'Payload', + type: 'text', + placeholder: 'Payload', + }, }, async authorize(credentials) { try { /** - * Receiving credentials from signIn() payload + * Receiving credentials from signIn() data */ const { message, signature, network = 'Evm', + payload = null, } = credentials as { message: string; signature: string; network: Network; + payload: string | null; }; const nextAuthUrl = process.env.NEXTAUTH_URL; @@ -85,7 +95,7 @@ const MoralisNextAuthProvider = () => /** * Defining and returning user profile */ - return user; + return { ...user, payload }; } catch (e) { const logger = new LoggerController('Next', Moralis.Core.config); logger.error(e);