Fix: Middlerawe/1
This commit is contained in:
@@ -3,7 +3,7 @@ import { NextResponse } from "next/server";
|
|||||||
|
|
||||||
export async function GET() {
|
export async function GET() {
|
||||||
cookies().set({
|
cookies().set({
|
||||||
name: "ssn",
|
name: "mySession",
|
||||||
value: "",
|
value: "",
|
||||||
maxAge: 0,
|
maxAge: 0,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ export async function POST(req: Request) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
cookies().set({
|
cookies().set({
|
||||||
name: "ssn",
|
name: "mySession",
|
||||||
value: seal,
|
value: seal,
|
||||||
maxAge: 60 * 60 * 24 * 7,
|
maxAge: 60 * 60 * 24 * 7,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -35,10 +35,9 @@ export async function POST(req: Request) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
cookies().set({
|
cookies().set({
|
||||||
name: "ssn",
|
name: "mySession",
|
||||||
value: res,
|
value: res,
|
||||||
maxAge: 60 * 60 * 24 * 7,
|
maxAge: 60 * 60 * 24 * 7,
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
revalidatePath("/dev/home");
|
revalidatePath("/dev/home");
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { NextResponse } from "next/server";
|
|||||||
|
|
||||||
export async function GET(req: Request) {
|
export async function GET(req: Request) {
|
||||||
const cekCookies = cookies();
|
const cekCookies = cookies();
|
||||||
const c = cekCookies.get("ssn");
|
const c = cekCookies.get("mySession");
|
||||||
|
|
||||||
if (!c || !c?.value || _.isEmpty(c?.value) || _.isUndefined(c?.value)) {
|
if (!c || !c?.value || _.isEmpty(c?.value) || _.isUndefined(c?.value)) {
|
||||||
return NextResponse.json({ success: false });
|
return NextResponse.json({ success: false });
|
||||||
|
|||||||
@@ -41,15 +41,15 @@ export default async function RootLayout({
|
|||||||
}: {
|
}: {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
}) {
|
}) {
|
||||||
// const userLoginId = await funGetUserIdByToken();
|
const userLoginId = await funGetUserIdByToken();
|
||||||
|
|
||||||
// if (!token) return <>Require Token Storage</>;
|
if (!token) return <>Require Token Storage</>;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<RootStyleRegistry>
|
<RootStyleRegistry>
|
||||||
{/* <MqttLoader />
|
{/* <MqttLoader />
|
||||||
<TokenProvider token={token} envObject={envObject} /> */}
|
<TokenProvider token={token} envObject={envObject} /> */}
|
||||||
{/* <RealtimeProvider userLoginId={userLoginId as string} /> */}
|
<RealtimeProvider userLoginId={userLoginId as string} />
|
||||||
{children}
|
{children}
|
||||||
</RootStyleRegistry>
|
</RootStyleRegistry>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import _ from "lodash";
|
|||||||
import { cookies } from "next/headers";
|
import { cookies } from "next/headers";
|
||||||
|
|
||||||
export async function funCheckToken() {
|
export async function funCheckToken() {
|
||||||
const c = cookies().get("ssn");
|
const c = cookies().get("mySession");
|
||||||
const cekToken = await prisma.userSession.findFirst({
|
const cekToken = await prisma.userSession.findFirst({
|
||||||
where: {
|
where: {
|
||||||
token: c?.value,
|
token: c?.value,
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import prisma from "@/app/lib/prisma";
|
|||||||
import { cookies } from "next/headers";
|
import { cookies } from "next/headers";
|
||||||
|
|
||||||
export async function funGetUserIdByToken() {
|
export async function funGetUserIdByToken() {
|
||||||
const c = cookies().get("ssn");
|
const c = cookies().get("mySession");
|
||||||
const token = c?.value
|
const token = c?.value
|
||||||
const cekToken = await prisma.userSession.findFirst({
|
const cekToken = await prisma.userSession.findFirst({
|
||||||
where: {
|
where: {
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ export async function auth_Logout() {
|
|||||||
if (!delToken) return { status: 400, message: "Gagal Hapus User Session" };
|
if (!delToken) return { status: 400, message: "Gagal Hapus User Session" };
|
||||||
|
|
||||||
cookies().delete({
|
cookies().delete({
|
||||||
name: "ssn",
|
name: "mySession",
|
||||||
});
|
});
|
||||||
return { status: 200, message: "Logout Berhasil" };
|
return { status: 200, message: "Logout Berhasil" };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ export async function Auth_funRegister({
|
|||||||
);
|
);
|
||||||
|
|
||||||
cookies().set({
|
cookies().set({
|
||||||
name: "ssn",
|
name: "mySession",
|
||||||
value: sealToken,
|
value: sealToken,
|
||||||
maxAge: 60 * 60 * 24 * 7,
|
maxAge: 60 * 60 * 24 * 7,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ export async function auth_funValidasi({
|
|||||||
);
|
);
|
||||||
|
|
||||||
cookies().set({
|
cookies().set({
|
||||||
name: "ssn",
|
name: "mySession",
|
||||||
value: sealToken,
|
value: sealToken,
|
||||||
maxAge: 60 * 60 * 24 * 30,
|
maxAge: 60 * 60 * 24 * 30,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import { redirect } from "next/navigation";
|
|||||||
export async function user_funGetOneUserId(): Promise<string | null> {
|
export async function user_funGetOneUserId(): Promise<string | null> {
|
||||||
try {
|
try {
|
||||||
const kukis = cookies();
|
const kukis = cookies();
|
||||||
const c = kukis.get("ssn");
|
const c = kukis.get("mySession");
|
||||||
if (!c || !c?.value || _.isEmpty(c?.value) || _.isUndefined(c?.value))
|
if (!c || !c?.value || _.isEmpty(c?.value) || _.isUndefined(c?.value))
|
||||||
return redirect(RouterAuth.login);
|
return redirect(RouterAuth.login);
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,27 @@
|
|||||||
import { NextResponse } from "next/server";
|
import _ from "lodash";
|
||||||
import type { NextRequest } from "next/server";
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
|
|
||||||
// This function can be marked `async` if using `await` inside
|
// This function can be marked `async` if using `await` inside
|
||||||
export function middleware(request: NextRequest) {
|
export function middleware(request: NextRequest) {
|
||||||
return NextResponse.redirect(new URL("/home", request.url));
|
let cookies = request.cookies.get("mySession");
|
||||||
|
console.log(cookies);
|
||||||
|
|
||||||
|
if (
|
||||||
|
!cookies ||
|
||||||
|
!cookies?.value ||
|
||||||
|
_.isEmpty(cookies?.value) ||
|
||||||
|
_.isUndefined(cookies?.value)
|
||||||
|
) {
|
||||||
|
return NextResponse.redirect(new URL("/", request.url));
|
||||||
|
}
|
||||||
|
|
||||||
|
// return NextResponse.redirect(new URL("/", request.url));
|
||||||
}
|
}
|
||||||
|
|
||||||
// See "Matching Paths" below to learn more
|
// See "Matching Paths" below to learn more
|
||||||
export const config = {
|
export const config = {
|
||||||
matcher: "/about/:path*",
|
matcher: [
|
||||||
|
|
||||||
|
"/((?!_next|static|favicon.ico|manifest).*)",
|
||||||
|
],
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user