SteemPro x NextAuth

in hive-151113 •  9 months ago 

Hello devs,

Setting the high-security login method was a tough task in SteemPro. Today I completed the authentication logic. The hurdle was to get the login username during the server-side rendering. I did some research and decided to implement the Next Auth with a custom credentials login.

image.png

Only the sign-in option is required. So I add to login to Next Auth only with the username. Encrypted Private was not added to the auth as it's sensitive information even if it is encrypted. So I decided to keep the encrypted private key to local storage and use the Next auth login session to get the username on the server-side rendering.

Server-side rendering is used in NextJs to set the metadata and also to improve the overall performance of the app. Today I also covered the error boundary and loading states.

here is the simple implementation of the Next Auth.

import NextAuth from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials"
const handler = NextAuth({
session: {
strategy: 'jwt',
},
providers: [
CredentialsProvider({
name: 'SteemPro Authenticator',
credentials: {
username: {},
},
async authorize(credentials, req) {
if (credentials) {
return {
id: credentials.username,
name: credentials.username,
};
}
return null
}
})
],
});
export { handler as GET, handler as POST };


Cc: @blacks
Cc: @rme
Cc: @hungry-griffin
Cc: @steemchiller
Cc: @steemcurator01
Cc: @pennsif
Cc: @future.witness
Cc: @stephenkendal
Cc: @justyy
Cc: @upvu
Cc: @h4lab


VOTE @faisalamin as witness

🇸‌🇹‌🇪‌🇪‌🇲‌🇵‌🇷‌🇴‌


Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Upvoted! Thank you for supporting witness @jswit.