upd: auth
Deskripsi: - update log user pada edit profile, login, dan logout No Issues
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
|
import { createLogUser } from "@/module/user";
|
||||||
import { cookies } from "next/headers";
|
import { cookies } from "next/headers";
|
||||||
|
|
||||||
export async function DELETE() {
|
export async function DELETE() {
|
||||||
|
const log = await createLogUser({ act: 'LOGOUT', desc: 'User keluar dari program', table: 'user', data: '' })
|
||||||
|
|
||||||
cookies().delete('sessionCookieSDM')
|
cookies().delete('sessionCookieSDM')
|
||||||
|
|
||||||
return Response.json({ success: true })
|
return Response.json({ success: true })
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import _ from "lodash";
|
|||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
|
import { createLogUser } from "@/module/user";
|
||||||
|
|
||||||
|
|
||||||
// GET PROFILE BY COOKIES
|
// GET PROFILE BY COOKIES
|
||||||
@@ -139,6 +140,8 @@ export async function PUT(request: Request) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const log = await createLogUser({ act: 'UPDATE', desc: 'User mengupdate data profile', table: 'user', data: user.id })
|
||||||
|
|
||||||
return NextResponse.json({ success: true, message: "Berhasil ubah profile" });
|
return NextResponse.json({ success: true, message: "Berhasil ubah profile" });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return NextResponse.json({ success: false, message: "Gagal ubah profile" }, { status: 500 });
|
return NextResponse.json({ success: false, message: "Gagal ubah profile" }, { status: 500 });
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
import { sealData } from "iron-session";
|
import { sealData } from "iron-session";
|
||||||
import { cookies } from "next/headers";
|
import { cookies } from "next/headers";
|
||||||
import { prisma, pwd_key_config } from "@/module/_global";
|
import { prisma, pwd_key_config } from "@/module/_global";
|
||||||
|
import { createLogUser } from "@/module/user";
|
||||||
|
|
||||||
export default async function funSetCookies({ user }: { user: string }) {
|
export default async function funSetCookies({ user }: { user: string }) {
|
||||||
try {
|
try {
|
||||||
@@ -12,7 +13,7 @@ export default async function funSetCookies({ user }: { user: string }) {
|
|||||||
where: {
|
where: {
|
||||||
id: user
|
id: user
|
||||||
},
|
},
|
||||||
select:{
|
select: {
|
||||||
isFirstLogin: true
|
isFirstLogin: true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -34,7 +35,7 @@ export default async function funSetCookies({ user }: { user: string }) {
|
|||||||
value: encryptedUserData,
|
value: encryptedUserData,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const log = await createLogUser({ act: 'LOGIN', desc: 'User masuk ke program', table: 'user', data: '' })
|
||||||
|
|
||||||
return { success: true, message: "Login berhasil!", pertamaLogin: dataUser?.isFirstLogin };
|
return { success: true, message: "Login berhasil!", pertamaLogin: dataUser?.isFirstLogin };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ export default function Profile() {
|
|||||||
await fetch('/api/auth/logout', {
|
await fetch('/api/auth/logout', {
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
});
|
});
|
||||||
toast.success('Logout Success')
|
toast.success('Logout Sukses')
|
||||||
window.location.href = '/';
|
window.location.href = '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user