mirror of
https://github.com/i701/sarlink-portal.git
synced 2025-06-29 15:47:09 +00:00
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
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 6m26s
This commit is contained in:
@ -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"
|
||||
|
18
app/auth.ts
18
app/auth.ts
@ -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(
|
||||
|
Reference in New Issue
Block a user