mirror of
https://github.com/ramvignesh-b/pi-ku.git
synced 2026-05-04 19:10:52 +00:00
refactor: centralize API endpoints and token refresh logic
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import { CheckCircleIcon, XCircleIcon } from "@phosphor-icons/react";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { useNavigate, useParams } from "react-router-dom";
|
||||
import authApiClient from "../api/apiClient";
|
||||
import { preAuthApiClient } from "../api/apiClient";
|
||||
import Logo from "../components/Logo";
|
||||
import { endpoints, replacePathParams } from "../config/endpoints";
|
||||
import { ROUTES } from "../config/routes";
|
||||
|
||||
export default function Activate() {
|
||||
const { uidb64, token } = useParams();
|
||||
@@ -20,7 +22,11 @@ export default function Activate() {
|
||||
|
||||
const activateAccount = async () => {
|
||||
try {
|
||||
await authApiClient.get(`/activate/${uidb64}/${token}/`);
|
||||
const url = replacePathParams(endpoints.ACTIVATE, {
|
||||
uidb64,
|
||||
token,
|
||||
});
|
||||
await preAuthApiClient.get(url);
|
||||
setStatus("success");
|
||||
} catch (err) {
|
||||
console.error("Activation error:", err);
|
||||
@@ -80,7 +86,7 @@ export default function Activate() {
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-ghost w-full"
|
||||
onClick={() => navigate("/onboard")}
|
||||
onClick={() => navigate(ROUTES.ONBOARD)}
|
||||
>
|
||||
Back to Registration
|
||||
</button>
|
||||
|
||||
@@ -5,9 +5,10 @@ import { useState } from "react";
|
||||
import { useForm } from "react-hook-form";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { z } from "zod";
|
||||
import authApiClient from "../api/apiClient";
|
||||
import { preAuthApiClient } from "../api/apiClient";
|
||||
import Logo from "../components/Logo";
|
||||
import FormField from "../components/ui/FormField";
|
||||
import { endpoints } from "../config/endpoints";
|
||||
|
||||
// validation logic
|
||||
const registerSchema = z
|
||||
@@ -41,7 +42,7 @@ export default function Register() {
|
||||
setIsLoading(true);
|
||||
setApiError(null);
|
||||
try {
|
||||
await authApiClient.post("/register/", {
|
||||
await preAuthApiClient.post(endpoints.REGISTER, {
|
||||
full_name: data.full_name,
|
||||
email: data.email,
|
||||
password: data.password,
|
||||
|
||||
Reference in New Issue
Block a user