Compare commits

...

1 Commits

Author SHA1 Message Date
091c33a73c Test Hapus Auth 2025-11-27 18:13:29 +08:00
28 changed files with 22 additions and 21 deletions

View File

@@ -1,5 +1,6 @@
'use client'; 'use client';
import { apiFetchLogin } from '@/app/api/auth/_lib/api_fetch_auth';
import { apiFetchLogin } from '@/app/api/[auth]/_lib/api_fetch_auth';
import colors from '@/con/colors'; import colors from '@/con/colors';
import { Box, Button, Center, Image, Paper, Stack, Title } from '@mantine/core'; import { Box, Button, Center, Image, Paper, Stack, Title } from '@mantine/core';
import { useRouter } from 'next/navigation'; import { useRouter } from 'next/navigation';

View File

@@ -1,7 +1,7 @@
// app/registrasi/page.tsx // app/registrasi/page.tsx
'use client'; 'use client';
import { apiFetchRegister } from '@/app/api/auth/_lib/api_fetch_auth'; import { apiFetchRegister } from '@/app/api/[auth]/_lib/api_fetch_auth';
import BackButton from '@/app/darmasaba/(pages)/desa/layanan/_com/BackButto'; import BackButton from '@/app/darmasaba/(pages)/desa/layanan/_com/BackButto';
import colors from '@/con/colors'; import colors from '@/con/colors';
import { import {

View File

@@ -31,7 +31,7 @@ export default function Validasi() {
useEffect(() => { useEffect(() => {
const checkFlow = async () => { const checkFlow = async () => {
try { try {
const res = await fetch('/api/auth/get-flow', { const res = await fetch('/api/get-flow', {
credentials: 'include' credentials: 'include'
}); });
const data = await res.json(); const data = await res.json();
@@ -60,7 +60,7 @@ export default function Validasi() {
setKodeId(storedKodeId); setKodeId(storedKodeId);
const loadOtpData = async () => { const loadOtpData = async () => {
try { try {
const res = await fetch(`/api/auth/otp-data?kodeId=${encodeURIComponent(storedKodeId)}`); const res = await fetch(`/api/otp-data?kodeId=${encodeURIComponent(storedKodeId)}`);
const result = await res.json(); const result = await res.json();
if (res.ok && result.data?.nomor) { if (res.ok && result.data?.nomor) {
@@ -110,7 +110,7 @@ export default function Validasi() {
return; return;
} }
const verifyRes = await fetch('/api/auth/verify-otp-register', { const verifyRes = await fetch('/api/verify-otp-register', {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ nomor: cleanNomor, otp, kodeId }), body: JSON.stringify({ nomor: cleanNomor, otp, kodeId }),
@@ -123,7 +123,7 @@ export default function Validasi() {
return; return;
} }
const finalizeRes = await fetch('/api/auth/finalize-registration', { const finalizeRes = await fetch('/api/finalize-registration', {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ nomor, username, kodeId }), body: JSON.stringify({ nomor, username, kodeId }),
@@ -142,7 +142,7 @@ export default function Validasi() {
}; };
const handleLoginVerification = async () => { const handleLoginVerification = async () => {
const loginRes = await fetch('/api/auth/verify-otp-login', { const loginRes = await fetch('/api/verify-otp-login', {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ nomor, otp, kodeId }), body: JSON.stringify({ nomor, otp, kodeId }),
@@ -200,7 +200,7 @@ export default function Validasi() {
// Clear cookie // Clear cookie
try { try {
await fetch('/api/auth/clear-flow', { await fetch('/api/clear-flow', {
method: 'POST', method: 'POST',
credentials: 'include' credentials: 'include'
}); });
@@ -212,7 +212,7 @@ export default function Validasi() {
const handleResend = async () => { const handleResend = async () => {
if (!nomor) return; if (!nomor) return;
try { try {
const res = await fetch('/api/auth/resend', { const res = await fetch('/api/resend', {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ nomor }), body: JSON.stringify({ nomor }),

View File

@@ -49,7 +49,7 @@ export default function Layout({ children }: { children: React.ReactNode }) {
useEffect(() => { useEffect(() => {
const fetchUser = async () => { const fetchUser = async () => {
try { try {
const res = await fetch('/api/auth/me'); const res = await fetch('/api/me');
const data = await res.json(); const data = await res.json();
if (data.user) { if (data.user) {
@@ -114,7 +114,7 @@ export default function Layout({ children }: { children: React.ReactNode }) {
setIsLoggingOut(true); setIsLoggingOut(true);
// ✅ Panggil API logout untuk clear session di server // ✅ Panggil API logout untuk clear session di server
const response = await fetch('/api/auth/logout', { method: 'POST' }); const response = await fetch('/api/logout', { method: 'POST' });
const result = await response.json(); const result = await response.json();
if (result.success) { if (result.success) {

View File

@@ -1,7 +1,7 @@
/* eslint-disable @typescript-eslint/no-unused-vars */ /* eslint-disable @typescript-eslint/no-unused-vars */
// app/api/auth/_lib/api_fetch_auth.ts // app/api/_lib/api_fetch_auth.ts
// app/api/auth/_lib/api_fetch_auth.ts // app/api/_lib/api_fetch_auth.ts
export const apiFetchLogin = async ({ nomor }: { nomor: string }) => { export const apiFetchLogin = async ({ nomor }: { nomor: string }) => {
if (!nomor || nomor.replace(/\D/g, '').length < 10) { if (!nomor || nomor.replace(/\D/g, '').length < 10) {
@@ -10,7 +10,7 @@ export const apiFetchLogin = async ({ nomor }: { nomor: string }) => {
const cleanPhone = nomor.replace(/\D/g, ''); const cleanPhone = nomor.replace(/\D/g, '');
const response = await fetch("/api/auth/login", { const response = await fetch("/api/login", {
method: "POST", method: "POST",
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },
body: JSON.stringify({ nomor: cleanPhone }), body: JSON.stringify({ nomor: cleanPhone }),
@@ -22,7 +22,7 @@ export const apiFetchLogin = async ({ nomor }: { nomor: string }) => {
try { try {
data = await response.json(); data = await response.json();
} catch (e) { } catch (e) {
console.error("Non-JSON response from /api/auth/login:", await response.text()); console.error("Non-JSON response from /api/login:", await response.text());
throw new Error('Respons server tidak valid'); throw new Error('Respons server tidak valid');
} }
@@ -55,7 +55,7 @@ export const apiFetchRegister = async ({
const cleanPhone = nomor.replace(/\D/g, ''); const cleanPhone = nomor.replace(/\D/g, '');
if (cleanPhone.length < 10) throw new Error('Nomor tidak valid'); if (cleanPhone.length < 10) throw new Error('Nomor tidak valid');
const response = await fetch("/api/auth/register", { const response = await fetch("/api/register", {
method: "POST", method: "POST",
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },
body: JSON.stringify({ username: username.trim(), nomor: cleanPhone }), body: JSON.stringify({ username: username.trim(), nomor: cleanPhone }),
@@ -73,7 +73,7 @@ export const apiFetchOtpData = async ({ kodeId }: { kodeId: string }) => {
throw new Error('Kode ID tidak valid'); throw new Error('Kode ID tidak valid');
} }
const response = await fetch("/api/auth/otp-data", { const response = await fetch("/api/otp-data", {
method: "POST", method: "POST",
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },
body: JSON.stringify({ kodeId }), body: JSON.stringify({ kodeId }),
@@ -90,7 +90,7 @@ export const apiFetchOtpData = async ({ kodeId }: { kodeId: string }) => {
// Ganti endpoint ke verify-otp-login // Ganti endpoint ke verify-otp-login
export const apiFetchVerifyOtp = async ({ nomor, otp, kodeId }: { nomor: string; otp: string; kodeId: string }) => { export const apiFetchVerifyOtp = async ({ nomor, otp, kodeId }: { nomor: string; otp: string; kodeId: string }) => {
const response = await fetch('/api/auth/verify-otp-login', { const response = await fetch('/api/verify-otp-login', {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ nomor, otp, kodeId }), body: JSON.stringify({ nomor, otp, kodeId }),

View File

@@ -50,7 +50,7 @@ export async function GET() {
}, },
}); });
} catch (error) { } catch (error) {
console.error("❌ Error in /api/auth/me:", error); console.error("❌ Error in /api/me:", error);
return NextResponse.json( return NextResponse.json(
{ success: false, message: "Internal server error", user: null }, { success: false, message: "Internal server error", user: null },
{ status: 500 } { status: 500 }

View File

@@ -16,7 +16,7 @@ import { useEffect, useState } from 'react';
import { authStore } from '@/store/authStore'; // ✅ integrasi authStore import { authStore } from '@/store/authStore'; // ✅ integrasi authStore
async function fetchUser() { async function fetchUser() {
const res = await fetch('/api/auth/me'); const res = await fetch('/api/me');
if (!res.ok) { if (!res.ok) {
const text = await res.text(); const text = await res.text();
throw new Error(`HTTP ${res.status}: ${text}`); throw new Error(`HTTP ${res.status}: ${text}`);
@@ -77,7 +77,7 @@ export default function WaitingRoom() {
// Force a session refresh // Force a session refresh
try { try {
const res = await fetch('/api/auth/refresh-session', { const res = await fetch('/api/refresh-session', {
method: 'POST', method: 'POST',
credentials: 'include' credentials: 'include'
}); });