Skip to content
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

feat: added payload parameter to MoralisNextAuthProvider. #946

Merged
merged 2 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/soft-bananas-applaud.md
Original file line number Diff line number Diff line change
@@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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('/');
Expand Down
1 change: 1 addition & 0 deletions demos/nextjs/app/components/modules/Profile/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const Profile: FC = () => {
<Image src="/assets/mage.svg" width={46} height={46} alt="profile" />
<h4>{data?.user?.address}</h4>
<p>Profile ID: {data?.user.profileId}</p>
<p>Payload: {data?.user.payload}</p>
<p>Native Balance: {balance?.balance.ether} Ether</p>
</div>
);
Expand Down
14 changes: 12 additions & 2 deletions packages/next/src/auth/MoralisNextAuthProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down