Skip to content

Commit

Permalink
feat: added payload parameter to MoralisNextAuthProvider. (#946)
Browse files Browse the repository at this point in the history
  • Loading branch information
b4rtaz authored Jan 5, 2023
1 parent 11b751d commit dc3f662
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
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

1 comment on commit dc3f662

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test coverage

Title Lines Statements Branches Functions
api-utils Coverage: 25%
26.34% (49/186) 19.14% (9/47) 22.85% (8/35)
auth Coverage: 90%
92.77% (77/83) 81.81% (18/22) 90% (18/20)
evm-api Coverage: 100%
100% (81/81) 66.66% (6/9) 100% (49/49)
common-evm-utils Coverage: 64%
64.67% (974/1506) 19.44% (127/653) 35.25% (208/590)
sol-api Coverage: 96%
96.66% (29/30) 66.66% (6/9) 91.66% (11/12)
common-sol-utils Coverage: 74%
73.77% (135/183) 60% (12/20) 65.67% (44/67)
common-streams-utils Coverage: 93%
94% (1066/1134) 81.42% (399/490) 86.74% (373/430)
streams Coverage: 89%
89.35% (512/573) 68.05% (49/72) 88.98% (105/118)

Please sign in to comment.