Skip to content

Commit

Permalink
sign in working
Browse files Browse the repository at this point in the history
  • Loading branch information
sharayu committed Jul 16, 2024
1 parent 3347d42 commit a84b28b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 7 additions & 6 deletions next-app/pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { SiweMessage } from "siwe"
// For more information on each option (and a full list of options) go to
// https://next-auth.js.org/configuration/options
export default async function auth(req: any, res: any) {

console.log("req: ", req);
const providers = [
CredentialsProvider({
name: "Ethereum",
Expand All @@ -24,12 +26,11 @@ export default async function auth(req: any, res: any) {
async authorize(credentials) {
try {
const siwe = new SiweMessage(JSON.parse(credentials?.message || "{}"))
const nextAuthUrl = process.env.VERCEL_URL ? new URL(process.env.VERCEL_URL) : null;
const nextAuthUrl = process.env.NEXTAUTH_URL ? new URL(process.env.NEXTAUTH_URL) : process.env.VERCEL_URL ? new URL(process.env.VERCEL_URL) : null;

if (!nextAuthUrl) {
return null
}

const result = await siwe.verify({
signature: credentials?.signature || "",
domain: nextAuthUrl.host,
Expand All @@ -43,28 +44,28 @@ export default async function auth(req: any, res: any) {
}
return null
} catch (e) {
console.log("eee: ", e);
return null
}
},
}),
]

const isDefaultSigninPage =
req.method === "GET" && req.query.nextauth.includes("signin")
req.method === "GET"

// Hide Sign-In with Ethereum from default sign page
if (isDefaultSigninPage) {
console.log("provider 1: ", providers);
providers.pop()
console.log("provider 1: ", providers);
}

return await NextAuth(req, res, {
// https://next-auth.js.org/configuration/providers/oauth
providers,
session: {
strategy: "jwt",
},
jwt: {
secret: process.env.JWT_SECRET,
},
secret: process.env.NEXTAUTH_SECRET,
callbacks: {
Expand Down
4 changes: 2 additions & 2 deletions next-app/pages/factor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export default function ({}: Props) {
<Table textAlign={"center"}>
<Thead>
<Tr>
<Th color={"brand.quinary"}>File Name</Th>
<Th color={"brand.quinary"} width={"100px"}>File Name</Th>
<Th color={"brand.quinary"}>Date (YYYY-MM-DD)</Th>
<Th color={"brand.quinary"}>Seller Address</Th>
<Th color={"brand.quinary"}>File URL</Th>
Expand All @@ -211,7 +211,7 @@ export default function ({}: Props) {
uploadedInvoices.map((invoice: UploadedInvoice) => (
<Tbody color={"brand.secondary"} key={invoice._id}>
<Tr>
<Td>{invoice.fileName}</Td>
<Td maxWidth={"200px"}><Text textOverflow={"ellipsis"}>{invoice.fileName}</Text></Td>
<Td>{invoice.date_added.slice(0, 10)}</Td>
<Td fontSize={15}>
{/* <Center bg={"brand.quinary"} fontSize={15}> */}
Expand Down

0 comments on commit a84b28b

Please sign in to comment.