refactor: update authentication flow to use PIN instead of email/password, enhance OTP verification with NextAuth, and improve session handling in components
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 6m26s

This commit is contained in:
2025-04-05 11:50:39 +05:00
parent ef9f032366
commit dbdc1df7d5
5 changed files with 67 additions and 57 deletions

View File

@ -23,6 +23,7 @@ export default async function Devices({
<h3 className="text-sarLinkOrange text-2xl">My Devices</h3>
<AddDeviceDialogForm user_id={session?.user?.id} />
</div>
<pre>{JSON.stringify(session, null, 2)}</pre>
<div
id="user-filters"

View File

@ -22,28 +22,26 @@ export const authOptions: NextAuthOptions = {
CredentialsProvider({
name: "Credentials",
credentials: {
email: { label: "Email", type: "text", placeholder: "jsmith" },
password: { label: "Password", type: "password" },
pin: { label: "Pin", type: "text", placeholder: "000000" },
},
async authorize(credentials) {
const { email, password } = credentials as {
email: string;
password: string;
const { pin } = credentials as {
pin: string;
};
console.log("email and password", email, password);
console.log("pin", pin);
const res = await fetch(
`${process.env.NEXT_PUBLIC_API_URL}/auth/login/`,
`${process.env.SARLINK_API_BASE_URL}/callback/auth/`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
username: email,
password: password,
token: pin,
}),
},
);
console.log(res);
console.log("status", res.status);
const data = await res.json();
@ -53,7 +51,7 @@ export const authOptions: NextAuthOptions = {
return { ...data.user, apiToken: data.token, expiry: data.expiry };
case 400:
throw new Error(
JSON.stringify({ message: data.message, status: res.status }),
JSON.stringify({ message: data.token[0], status: res.status }),
);
case 429:
throw new Error(