51 lines
1.9 KiB
TypeScript
51 lines
1.9 KiB
TypeScript
|
|
|
|
// 'use server';
|
|
|
|
// import { NextRequest, NextResponse } from "next/server";
|
|
// import { getServerSession } from "next-auth";
|
|
// import { authOptions } from "@/app/lib/auth";
|
|
// import { getUMAToken } from "@/app/lib/keycloak";
|
|
// import { configs } from "@/app/config/configs";
|
|
|
|
// export async function POST(req: NextRequest) {
|
|
// const session = await getServerSession(authOptions);
|
|
|
|
// console.log(`a user is attempting to POST their profile. session as follows`)
|
|
// console.log(session)
|
|
|
|
// if (session) {
|
|
// if (!session.token?.access_token) {
|
|
// console.error('session.token.access_token was missing')
|
|
// return NextResponse.json({ error: `Failed to get access token from Session`}, { status: 500 })
|
|
// }
|
|
|
|
// const uma = await getUMAToken();
|
|
// const userId = session.user.id; // Assuming session.user.id is the Keycloak user ID
|
|
// const updatedAttributes = await req.json(); // Assuming the updated attributes are sent in the request body
|
|
|
|
// console.log('updatedAttributes as follows')
|
|
// console.log(updatedAttributes)
|
|
|
|
// const response = await fetch(`${configs.keycloakLocalUrl}/admin/realms/futureporn/users/${userId}`, {
|
|
// method: 'PUT',
|
|
// headers: {
|
|
// 'Authorization': `Bearer ${uma.access_token}`,
|
|
// 'Content-Type': 'application/json'
|
|
// },
|
|
// body: JSON.stringify({
|
|
// attributes: updatedAttributes
|
|
// })
|
|
// });
|
|
|
|
// // /admin/realms/futureporn/users/9dd538cd-56a9-4f43-81cd-fa86473214f5
|
|
|
|
// if (!response.ok) {
|
|
// console.error(`failed. res.status=${response.status} res.statusText=${response.statusText}`)
|
|
// return NextResponse.json({ error: 'Failed to update user attributes' }, { status: 500 });
|
|
// } else {
|
|
// return NextResponse.json({ message: 'User attributes updated successfully' });
|
|
// }
|
|
// }
|
|
// return NextResponse.json({ error: "You must be logged in." }, { status: 401 });
|
|
// }
|