fix middleware 3
This commit is contained in:
@@ -129,8 +129,11 @@ export const middleware = async (req: NextRequest) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// const origin = new URL(req.url).origin;
|
||||||
|
// console.log("origin", origin);
|
||||||
|
|
||||||
const validationResponse = await fetch(
|
const validationResponse = await fetch(
|
||||||
new URL(validationApiRoute, req.url),
|
`${new URL(req.url).origin}/api/validation`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -151,12 +154,15 @@ export const middleware = async (req: NextRequest) => {
|
|||||||
// Handle /dev routes that require active status
|
// Handle /dev routes that require active status
|
||||||
if (pathname.startsWith("/dev")) {
|
if (pathname.startsWith("/dev")) {
|
||||||
try {
|
try {
|
||||||
const userValidate = await fetch(new URL("/api/user-validate", req.url), {
|
const userValidate = await fetch(
|
||||||
headers: {
|
new URL(req.url).origin + "/api/user-validate",
|
||||||
"Content-Type": "application/json",
|
{
|
||||||
Authorization: `Bearer ${token}`,
|
headers: {
|
||||||
},
|
"Content-Type": "application/json",
|
||||||
});
|
Authorization: `Bearer ${token}`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
if (!userValidate.ok) {
|
if (!userValidate.ok) {
|
||||||
throw new Error("Failed to validate user");
|
throw new Error("Failed to validate user");
|
||||||
@@ -227,10 +233,13 @@ function unauthorizedResponse() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function unauthorizedResponseTokenAPI() {
|
function unauthorizedResponseTokenAPI() {
|
||||||
return new NextResponse(JSON.stringify({ error: "Unauthorized token on API" }), {
|
return new NextResponse(
|
||||||
status: 401,
|
JSON.stringify({ error: "Unauthorized token on API" }),
|
||||||
headers: { "Content-Type": "application/json" },
|
{
|
||||||
});
|
status: 401,
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function unauthorizedResponseTokenPAGE() {
|
function unauthorizedResponseTokenPAGE() {
|
||||||
|
|||||||
Reference in New Issue
Block a user