mirror of
https://github.com/fosrl/pangolin.git
synced 2025-12-15 12:36:36 +00:00
respond with relative code expiration time
This commit is contained in:
@@ -22,7 +22,7 @@ export type StartDeviceWebAuthBody = z.infer<typeof bodySchema>;
|
||||
|
||||
export type StartDeviceWebAuthResponse = {
|
||||
code: string;
|
||||
expiresAt: number;
|
||||
expiresInSeconds: number;
|
||||
};
|
||||
|
||||
// Helper function to generate device code in format A1AJ-N5JD
|
||||
@@ -131,10 +131,13 @@ export async function startDeviceWebAuth(
|
||||
createdAt: Date.now()
|
||||
});
|
||||
|
||||
// calculate relative expiration in seconds
|
||||
const expiresInSeconds = Math.floor((expiresAt - Date.now()) / 1000);
|
||||
|
||||
return response<StartDeviceWebAuthResponse>(res, {
|
||||
data: {
|
||||
code,
|
||||
expiresAt
|
||||
expiresInSeconds
|
||||
},
|
||||
success: true,
|
||||
error: false,
|
||||
|
||||
@@ -15,8 +15,6 @@ export default async function DeviceLoginPage({ searchParams }: Props) {
|
||||
const params = await searchParams;
|
||||
const code = params.code || "";
|
||||
|
||||
console.log("user", user);
|
||||
|
||||
if (!user) {
|
||||
const redirectDestination = code
|
||||
? `/auth/login/device?code=${encodeURIComponent(code)}`
|
||||
|
||||
@@ -84,6 +84,9 @@ export default function DeviceLoginForm({
|
||||
if (!data.code.includes("-") && data.code.length === 8) {
|
||||
data.code = data.code.slice(0, 4) + "-" + data.code.slice(4);
|
||||
}
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 300));
|
||||
|
||||
// First check - get metadata
|
||||
const res = await api.post(
|
||||
"/device-web-auth/verify?forceLogin=true",
|
||||
@@ -93,8 +96,6 @@ export default function DeviceLoginForm({
|
||||
}
|
||||
);
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 500)); // artificial delay for better UX
|
||||
|
||||
if (res.data.success && res.data.data.metadata) {
|
||||
setMetadata(res.data.data.metadata);
|
||||
setCode(data.code.toUpperCase());
|
||||
@@ -116,14 +117,14 @@ export default function DeviceLoginForm({
|
||||
setLoading(true);
|
||||
|
||||
try {
|
||||
await new Promise((resolve) => setTimeout(resolve, 300));
|
||||
|
||||
// Final verify
|
||||
await api.post("/device-web-auth/verify", {
|
||||
code: code,
|
||||
verify: true
|
||||
});
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 500)); // artificial delay for better UX
|
||||
|
||||
// Redirect to success page
|
||||
router.push("/auth/login/device/success");
|
||||
} catch (e: any) {
|
||||
|
||||
Reference in New Issue
Block a user