diff --git a/packages/web-ui/api/requests/super-admin/admin-add-ai-model.ts b/packages/web-ui/api/requests/super-admin/admin-add-ai-model.ts new file mode 100644 index 0000000..eb6a2e5 --- /dev/null +++ b/packages/web-ui/api/requests/super-admin/admin-add-ai-model.ts @@ -0,0 +1,31 @@ +import Endpoints from '@/api/endpoints'; +import { superAdminApiClient } from '@/api/superAdminApiClient'; +import { SuperAdminAddAiModelRequestDto } from '@/contract/ai/super-admin-add-ai-model.request.dto.d'; +import { SuperAdminAiModelResponseDto } from '@/contract/ai/super-admin-ai-model.response.dto.d'; + +export const adminAddAiModel = async ( + values: SuperAdminAddAiModelRequestDto, + superAdminEmail: string, + superAdminPassword: string +) => { + return new Promise(async (resolve, reject) => { + const res = await superAdminApiClient({ + url: Endpoints.admin.addAiModel(), + options: { + method: 'POST', + body: JSON.stringify({ + ...values, + }), + }, + superAdminEmail, + superAdminPassword, + }); + + if (!res.ok) { + const { error } = JSON.parse(await res.text()); + return reject(error); + } + + resolve(await res.json()); + }); +}; diff --git a/packages/web-ui/api/requests/super-admin/admin-get-ai-models.ts b/packages/web-ui/api/requests/super-admin/admin-get-ai-models.ts new file mode 100644 index 0000000..eb09116 --- /dev/null +++ b/packages/web-ui/api/requests/super-admin/admin-get-ai-models.ts @@ -0,0 +1,28 @@ +import Endpoints from '@/api/endpoints'; +import { superAdminApiClient } from '@/api/superAdminApiClient'; +import { SuperAdminAiModelResponseDto } from '@/contract/ai/super-admin-ai-model.response.dto.d'; + +export const ADMIN_GET_AI_MODELS_REQ_KEY = 'admin-ai-models'; + +export const adminGetAiModels = async ( + superAdminEmail: string, + superAdminPassword: string +) => { + return new Promise( + async (resolve, reject) => { + const res = await superAdminApiClient({ + url: Endpoints.admin.getAiModels(), + options: { method: 'GET' }, + superAdminEmail, + superAdminPassword, + }); + + if (!res.ok) { + const { error } = JSON.parse(await res.text()); + return reject(error); + } + + resolve(await res.json()); + } + ); +}; diff --git a/packages/web-ui/api/requests/super-admin/admin-get-all-users.ts b/packages/web-ui/api/requests/super-admin/admin-get-all-users.ts new file mode 100644 index 0000000..a494c48 --- /dev/null +++ b/packages/web-ui/api/requests/super-admin/admin-get-all-users.ts @@ -0,0 +1,26 @@ +import Endpoints from '@/api/endpoints'; +import { superAdminApiClient } from '@/api/superAdminApiClient'; +import { UserResponseDto } from '@/contract/auth/user.response.dto.d'; + +export const ADMIN_GET_ALL_USERS_REQ_KEY = 'admin-all-users'; + +export const adminGetAllUsers = async ( + superAdminEmail: string, + superAdminPassword: string +) => { + return new Promise(async (resolve, reject) => { + const res = await superAdminApiClient({ + url: Endpoints.admin.getUsers(), + options: { method: 'GET' }, + superAdminEmail, + superAdminPassword, + }); + + if (!res.ok) { + const { error } = JSON.parse(await res.text()); + return reject(error); + } + + resolve(await res.json()); + }); +}; diff --git a/packages/web-ui/api/requests/super-admin/update-user-roles.ts b/packages/web-ui/api/requests/super-admin/update-user-roles.ts new file mode 100644 index 0000000..0c4e70a --- /dev/null +++ b/packages/web-ui/api/requests/super-admin/update-user-roles.ts @@ -0,0 +1,33 @@ +import Endpoints from '@/api/endpoints'; +import { superAdminApiClient } from '@/api/superAdminApiClient'; +import { SuperAdminUpdateUserRoleRequestDto } from '@/contract/auth/super-admin-update-role.request.dto.d'; +import { UserResponseDto } from '@/contract/auth/user.response.dto.d'; + +export const updateUserRoles = async ( + userId: string, + values: Omit, + superAdminEmail: string, + superAdminPassword: string +) => { + return new Promise(async (resolve, reject) => { + const res = await superAdminApiClient({ + url: Endpoints.admin.updateUserRoles(), + options: { + method: 'POST', + body: JSON.stringify({ + userId, + ...values, + }), + }, + superAdminEmail, + superAdminPassword, + }); + + if (!res.ok) { + const { error } = JSON.parse(await res.text()); + return reject(error); + } + + resolve(await res.json()); + }); +}; diff --git a/packages/web-ui/api/requests/super-admin/validate-admin-credentials.ts b/packages/web-ui/api/requests/super-admin/validate-admin-credentials.ts new file mode 100644 index 0000000..655512e --- /dev/null +++ b/packages/web-ui/api/requests/super-admin/validate-admin-credentials.ts @@ -0,0 +1,21 @@ +import Endpoints from '@/api/endpoints'; +import { superAdminApiClient } from '@/api/superAdminApiClient'; +import { SuperAdminValidateCredentialsRequestDto } from '@/contract/auth/super-admin-validate-credentials.request.dto.d'; + +export const validateAdminCredentials = async ( + values: SuperAdminValidateCredentialsRequestDto +) => { + return new Promise(async (resolve, reject) => { + const res = await superAdminApiClient({ + url: Endpoints.admin.validateCredentials(), + options: { method: 'POST', body: JSON.stringify(values) }, + }); + + if (!res.ok) { + const { error } = JSON.parse(await res.text()); + return reject(error); + } + + resolve(); + }); +}; diff --git a/packages/web-ui/app/admin/layout.tsx b/packages/web-ui/app/admin/layout.tsx index 94e93ef..493e1ba 100644 --- a/packages/web-ui/app/admin/layout.tsx +++ b/packages/web-ui/app/admin/layout.tsx @@ -1,8 +1,9 @@ import '@/styles/globals.css'; -import { cookies, headers } from 'next/headers'; import { redirect } from 'next/navigation'; import Endpoints from '@/api/endpoints'; import { superAdminApiClient } from '@/api/superAdminApiClient'; +import { getSuperAdminCookieOnServer } from '@/utils/get-super-admin-cookie-server'; +import { getUrlPath } from '@/utils/get-url-path'; import { StateProvider } from '@/components/state-provider'; @@ -27,10 +28,8 @@ const validateSuperAdminCredentials = async ( }; export default async function SuperAdminLayout({ children }: RootLayoutProps) { - const nextCookies = cookies(); - const { get: getHeader } = headers(); - const adminCredentialsCookie = nextCookies.get('__admin'); - const urlPath = getHeader('x-invoke-path'); + const { adminCredentialsCookie } = getSuperAdminCookieOnServer(); + const { urlPath } = getUrlPath(); // If no cookie credentials -> redirect for login (but if in login already, don't redirect again) if (!adminCredentialsCookie && urlPath !== '/admin/login') { diff --git a/packages/web-ui/app/admin/login/page.tsx b/packages/web-ui/app/admin/login/page.tsx index b44a53e..482dc95 100644 --- a/packages/web-ui/app/admin/login/page.tsx +++ b/packages/web-ui/app/admin/login/page.tsx @@ -1,11 +1,11 @@ 'use client'; import { useRouter } from 'next/navigation'; -import Endpoints from '@/api/endpoints'; -import { superAdminApiClient } from '@/api/superAdminApiClient'; +import { validateAdminCredentials } from '@/api/requests/super-admin/validate-admin-credentials'; import { SuperAdminValidateCredentialsRequestSchema } from '@/contract/auth/super-admin-validate-credentials.request.dto'; import { SuperAdminValidateCredentialsRequestDto } from '@/contract/auth/super-admin-validate-credentials.request.dto.d'; import { zodResolver } from '@hookform/resolvers/zod'; +import { useMutation } from '@tanstack/react-query'; import { useForm } from 'react-hook-form'; import { Button } from '@/components/ui/button'; @@ -23,6 +23,19 @@ import { useToast } from '@/components/ui/use-toast'; export default function SuperAdminLogin() { const { toast } = useToast(); const router = useRouter(); + const { mutate: validateAdminCredentialsReq, isLoading } = useMutation({ + mutationFn: (values: SuperAdminValidateCredentialsRequestDto) => + validateAdminCredentials(values), + onError: (error: any) => { + toast({ + title: error, + variant: 'destructive', + }); + }, + onSuccess: (room) => { + router.push('/admin/manage/users'); + }, + }); const form = useForm({ resolver: zodResolver(SuperAdminValidateCredentialsRequestSchema), defaultValues: { @@ -31,21 +44,9 @@ export default function SuperAdminLogin() { }, }); - async function onSubmit(values: SuperAdminValidateCredentialsRequestDto) { + function onSubmit(values: SuperAdminValidateCredentialsRequestDto) { try { - const res = await superAdminApiClient({ - url: Endpoints.admin.validateCredentials(), - options: { method: 'POST', body: JSON.stringify(values) }, - }); - if (!res.ok) { - const { error } = JSON.parse(await res.text()); - toast({ - title: error, - variant: 'destructive', - }); - return; - } - router.push('/admin/manage/users'); + validateAdminCredentialsReq(values); } catch (e) { console.log(e); } @@ -84,7 +85,9 @@ export default function SuperAdminLogin() { )} />
- +
diff --git a/packages/web-ui/app/admin/manage/ai-models/layout.tsx b/packages/web-ui/app/admin/manage/ai-models/layout.tsx index a1c57ad..ae2351a 100644 --- a/packages/web-ui/app/admin/manage/ai-models/layout.tsx +++ b/packages/web-ui/app/admin/manage/ai-models/layout.tsx @@ -1,15 +1,11 @@ import '@/styles/globals.css'; -import { ReactNode } from 'react'; - import { AdminHeader } from '@/components/admin/admin-header'; -export default function AdminUsersLayout({ - children, - params, -}: { - children: ReactNode; - params: { room: string }; -}) { +interface RootLayoutProps { + children: React.ReactNode; +} + +export default function AdminUsersLayout({ children }: RootLayoutProps) { return (
diff --git a/packages/web-ui/app/admin/manage/ai-models/page.tsx b/packages/web-ui/app/admin/manage/ai-models/page.tsx index 2134a05..d3ea492 100644 --- a/packages/web-ui/app/admin/manage/ai-models/page.tsx +++ b/packages/web-ui/app/admin/manage/ai-models/page.tsx @@ -1,8 +1,9 @@ import React from 'react'; -import { cookies } from 'next/headers'; -import Endpoints from '@/api/endpoints'; -import { superAdminApiClient } from '@/api/superAdminApiClient'; -import { SuperAdminAiModelResponseDto } from '@/contract/ai/super-admin-ai-model.response.dto.d'; +import { + ADMIN_GET_AI_MODELS_REQ_KEY, + adminGetAiModels, +} from '@/api/requests/super-admin/admin-get-ai-models'; +import { getSuperAdminCookieOnServer } from '@/utils/get-super-admin-cookie-server'; import { Card } from '@/components/ui/card'; import { ScrollArea } from '@/components/ui/scroll-area'; @@ -17,34 +18,17 @@ import { } from '@/components/ui/table'; import { AddAiModelsForm } from '@/components/admin/add-ai-models-form'; import { HoverableTableCell } from '@/components/admin/hoverable-table-cell'; - -const getAiModels = async ( - superAdminEmail: string, - superAdminPassword: string -): Promise => { - try { - const res = await superAdminApiClient({ - url: Endpoints.admin.getAiModels(), - options: { method: 'GET' }, - superAdminEmail, - superAdminPassword, - }); - return res.json(); - } catch (e) { - console.log(e); - } - return []; -}; +import getQueryClient from '@/app/get-query-client'; export default async function AdminAiModels() { - const nextCookies = cookies(); - const adminCredentialsCookie = nextCookies.get('__admin'); + const { adminCredentialsCookie } = getSuperAdminCookieOnServer(); const adminCredentials = JSON.parse(adminCredentialsCookie!.value); - - const aiModels = await getAiModels( - adminCredentials.email, - adminCredentials.password - ); + const queryClient = getQueryClient(); + const aiModels = await queryClient.fetchQuery({ + queryKey: [ADMIN_GET_AI_MODELS_REQ_KEY], + queryFn: () => + adminGetAiModels(adminCredentials.email, adminCredentials.password), + }); return (
diff --git a/packages/web-ui/app/admin/manage/users/layout.tsx b/packages/web-ui/app/admin/manage/users/layout.tsx index 967f9b4..0a2276b 100644 --- a/packages/web-ui/app/admin/manage/users/layout.tsx +++ b/packages/web-ui/app/admin/manage/users/layout.tsx @@ -1,15 +1,11 @@ import '@/styles/globals.css'; -import { ReactNode } from 'react'; - import { AdminHeader } from '@/components/admin/admin-header'; -export default function AdminUsersLayout({ - children, - params, -}: { - children: ReactNode; - params: { room: string }; -}) { +interface RootLayoutProps { + children: React.ReactNode; +} + +export default function AdminUsersLayout({ children }: RootLayoutProps) { return (
diff --git a/packages/web-ui/app/admin/manage/users/page.tsx b/packages/web-ui/app/admin/manage/users/page.tsx index 3dca74a..702789d 100644 --- a/packages/web-ui/app/admin/manage/users/page.tsx +++ b/packages/web-ui/app/admin/manage/users/page.tsx @@ -1,8 +1,9 @@ import React from 'react'; -import { cookies } from 'next/headers'; -import Endpoints from '@/api/endpoints'; -import { superAdminApiClient } from '@/api/superAdminApiClient'; -import { UserResponseDto } from '@/contract/auth/user.response.dto.d'; +import { + ADMIN_GET_ALL_USERS_REQ_KEY, + adminGetAllUsers, +} from '@/api/requests/super-admin/admin-get-all-users'; +import { getSuperAdminCookieOnServer } from '@/utils/get-super-admin-cookie-server'; import { getUserEmail } from '@/utils/get-user-email'; import { alphaAscSortPredicate } from '@/utils/sort-predicates'; @@ -19,34 +20,17 @@ import { TableRow, } from '@/components/ui/table'; import { UpdateRolesForm } from '@/components/admin/update-roles-form'; - -const getUsers = async ( - superAdminEmail: string, - superAdminPassword: string -): Promise => { - try { - const res = await superAdminApiClient({ - url: Endpoints.admin.getUsers(), - options: { method: 'GET' }, - superAdminEmail, - superAdminPassword, - }); - return res.json(); - } catch (e) { - console.log(e); - } - return []; -}; +import getQueryClient from '@/app/get-query-client'; export default async function AdminUsers() { - const nextCookies = cookies(); - const adminCredentialsCookie = nextCookies.get('__admin'); + const { adminCredentialsCookie } = getSuperAdminCookieOnServer(); const adminCredentials = JSON.parse(adminCredentialsCookie!.value); - - const users = await getUsers( - adminCredentials.email, - adminCredentials.password - ); + const queryClient = getQueryClient(); + const users = await queryClient.fetchQuery({ + queryKey: [ADMIN_GET_ALL_USERS_REQ_KEY], + queryFn: () => + adminGetAllUsers(adminCredentials.email, adminCredentials.password), + }); return (
diff --git a/packages/web-ui/app/admin/page.tsx b/packages/web-ui/app/admin/page.tsx index 46a75f1..1a490e5 100644 --- a/packages/web-ui/app/admin/page.tsx +++ b/packages/web-ui/app/admin/page.tsx @@ -1,11 +1,11 @@ -import { cookies, headers } from 'next/headers'; import { redirect } from 'next/navigation'; +import { getSuperAdminCookieOnServer } from '@/utils/get-super-admin-cookie-server'; +import { getUrlPath } from '@/utils/get-url-path'; export default async function AdminDashboard() { - const nextCookies = cookies(); - const { get: getHeader } = headers(); - const adminCredentialsCookie = nextCookies.get('__admin'); - const urlPath = getHeader('x-invoke-path'); + const { adminCredentialsCookie } = getSuperAdminCookieOnServer(); + const { urlPath } = getUrlPath(); + if (adminCredentialsCookie && urlPath === '/admin') { redirect('/admin/manage/users'); } diff --git a/packages/web-ui/components/admin/add-ai-models-form.tsx b/packages/web-ui/components/admin/add-ai-models-form.tsx index 1bcf476..da20fa2 100644 --- a/packages/web-ui/components/admin/add-ai-models-form.tsx +++ b/packages/web-ui/components/admin/add-ai-models-form.tsx @@ -2,13 +2,12 @@ import React, { useState } from 'react'; import { useRouter } from 'next/navigation'; -import Endpoints from '@/api/endpoints'; -import { superAdminApiClient } from '@/api/superAdminApiClient'; +import { adminAddAiModel } from '@/api/requests/super-admin/admin-add-ai-model'; import { SuperAdminAddAiModelRequestSchema } from '@/contract/ai/super-admin-add-ai-model.request.dto'; import { SuperAdminAddAiModelRequestDto } from '@/contract/ai/super-admin-add-ai-model.request.dto.d'; -import { getAppRoles } from '@/utils/get-app-roles'; +import { getSuperAdminCookieOnClient } from '@/utils/get-super-admin-cookie-client'; import { zodResolver } from '@hookform/resolvers/zod'; -import { getCookie } from 'cookies-next'; +import { useMutation } from '@tanstack/react-query'; import { Info } from 'lucide-react'; import { useForm } from 'react-hook-form'; import Textarea from 'react-textarea-autosize'; @@ -38,18 +37,34 @@ import { Input } from '@/components/ui/input'; import { Separator } from '@/components/ui/separator'; import { useToast } from '@/components/ui/use-toast'; -const roles = getAppRoles().map((role) => ({ id: role, label: role })); - export function AddAiModelsForm() { const [open, setOpen] = useState(false); const { toast } = useToast(); const router = useRouter(); - const adminCredentialsCookie = getCookie('__admin'); - let adminCredentials: { email: string; password: string }; - if (adminCredentialsCookie) { - adminCredentials = JSON.parse(adminCredentialsCookie.toString()); - } - + const { adminCredentialsCookie } = getSuperAdminCookieOnClient(); + const { mutate: addAiModelReq, isLoading } = useMutation({ + mutationFn: (values: SuperAdminAddAiModelRequestDto) => + adminAddAiModel( + values, + adminCredentialsCookie?.email ?? '', + adminCredentialsCookie?.password ?? '' + ), + onError: (error: any) => { + toast({ + title: error, + variant: 'destructive', + }); + }, + onSuccess: (room) => { + setOpen(false); + toast({ + title: 'AI Model added successfully!', + }); + form.reset(); + // this refresh next server component https://nextjs.org/docs/app/api-reference/functions/use-router + router.refresh(); + }, + }); const form = useForm({ resolver: zodResolver(SuperAdminAddAiModelRequestSchema), values: { @@ -64,37 +79,12 @@ export function AddAiModelsForm() { }, }); - async function onSubmit(values: SuperAdminAddAiModelRequestDto) { + function onSubmit(values: SuperAdminAddAiModelRequestDto) { try { if (values.alias!.trim().length === 0) { values.alias = undefined; } - const res = await superAdminApiClient({ - url: Endpoints.admin.addAiModel(), - options: { - method: 'POST', - body: JSON.stringify({ - ...values, - }), - }, - superAdminEmail: adminCredentials?.email, - superAdminPassword: adminCredentials?.password, - }); - if (!res.ok) { - const { error } = JSON.parse(await res.text()); - toast({ - title: error, - variant: 'destructive', - }); - return; - } - setOpen(false); - toast({ - title: 'AI Model added successfully!', - }); - form.reset(); - // this refresh next server component https://nextjs.org/docs/app/api-reference/functions/use-router - router.refresh(); + addAiModelReq(values); } catch (e) { console.log(e); } @@ -231,7 +221,9 @@ export function AddAiModelsForm() { )} />
- +
diff --git a/packages/web-ui/components/admin/admin-header.tsx b/packages/web-ui/components/admin/admin-header.tsx index 1575013..ccccbda 100644 --- a/packages/web-ui/components/admin/admin-header.tsx +++ b/packages/web-ui/components/admin/admin-header.tsx @@ -2,23 +2,18 @@ import { usePathname } from 'next/navigation'; -interface RoomHeaderProps { - id: string; - name: string; -} - function getTitleByPathname(pathName: string) { const parts = pathName.split('/'); const relevantParts = parts.filter((part) => !part.includes('admin')); return relevantParts.join(' '); } -export function AdminHeader({ id, name }: RoomHeaderProps) { +export function AdminHeader() { const pathname = usePathname(); return (
-

+

{getTitleByPathname(pathname)}

diff --git a/packages/web-ui/components/admin/update-roles-form.tsx b/packages/web-ui/components/admin/update-roles-form.tsx index b942ab7..4f72c18 100644 --- a/packages/web-ui/components/admin/update-roles-form.tsx +++ b/packages/web-ui/components/admin/update-roles-form.tsx @@ -2,13 +2,13 @@ import { useState } from 'react'; import { useRouter } from 'next/navigation'; -import Endpoints from '@/api/endpoints'; -import { superAdminApiClient } from '@/api/superAdminApiClient'; +import { updateUserRoles } from '@/api/requests/super-admin/update-user-roles'; import { SuperAdminUpdateUserRoleRequestSchema } from '@/contract/auth/super-admin-update-role.request.dto'; import { SuperAdminUpdateUserRoleRequestDto } from '@/contract/auth/super-admin-update-role.request.dto.d'; import { getAppRoles } from '@/utils/get-app-roles'; +import { getSuperAdminCookieOnClient } from '@/utils/get-super-admin-cookie-client'; import { zodResolver } from '@hookform/resolvers/zod'; -import { getCookie } from 'cookies-next'; +import { useMutation } from '@tanstack/react-query'; import { Settings } from 'lucide-react'; import { useForm } from 'react-hook-form'; @@ -47,12 +47,31 @@ export function UpdateRolesForm({ const [open, setOpen] = useState(false); const { toast } = useToast(); const router = useRouter(); - const adminCredentialsCookie = getCookie('__admin'); - let adminCredentials: { email: string; password: string }; - if (adminCredentialsCookie) { - adminCredentials = JSON.parse(adminCredentialsCookie.toString()); - } - + const { adminCredentialsCookie } = getSuperAdminCookieOnClient(); + const { mutate: updateUserRolesReq, isLoading } = useMutation({ + mutationFn: (values: Omit) => + updateUserRoles( + userId, + values, + adminCredentialsCookie?.email ?? '', + adminCredentialsCookie?.password ?? '' + ), + onError: (error: any) => { + toast({ + title: error, + variant: 'destructive', + }); + }, + onSuccess: (room) => { + setOpen(false); + toast({ + title: 'Roles updated successfully!', + }); + form.reset(); + // this refresh next server component https://nextjs.org/docs/app/api-reference/functions/use-router + router.refresh(); + }, + }); const form = useForm>({ resolver: zodResolver( SuperAdminUpdateUserRoleRequestSchema.omit({ userId: true }) @@ -62,37 +81,11 @@ export function UpdateRolesForm({ }, }); - async function onSubmit( + function onSubmit( values: Omit ) { try { - const res = await superAdminApiClient({ - url: Endpoints.admin.updateUserRoles(), - options: { - method: 'POST', - body: JSON.stringify({ - userId, - ...values, - }), - }, - superAdminEmail: adminCredentials?.email, - superAdminPassword: adminCredentials?.password, - }); - if (!res.ok) { - const { error } = JSON.parse(await res.text()); - toast({ - title: error, - variant: 'destructive', - }); - return; - } - setOpen(false); - toast({ - title: 'Roles updated successfully!', - }); - form.reset(); - // this refresh next server component https://nextjs.org/docs/app/api-reference/functions/use-router - router.refresh(); + updateUserRolesReq(values); } catch (e) { console.log(e); } @@ -160,7 +153,9 @@ export function UpdateRolesForm({ )} />
- +
diff --git a/packages/web-ui/utils/get-super-admin-cookie-client.ts b/packages/web-ui/utils/get-super-admin-cookie-client.ts new file mode 100644 index 0000000..968176f --- /dev/null +++ b/packages/web-ui/utils/get-super-admin-cookie-client.ts @@ -0,0 +1,15 @@ +import { getCookie } from 'cookies-next'; + +export function getSuperAdminCookieOnClient() { + let adminCredentialsCookie: { email: string; password: string } | undefined = + undefined; + const cookie = getCookie('__admin'); + + if (cookie) { + adminCredentialsCookie = JSON.parse(cookie.toString()); + } + + return { + adminCredentialsCookie, + }; +} diff --git a/packages/web-ui/utils/get-super-admin-cookie-server.ts b/packages/web-ui/utils/get-super-admin-cookie-server.ts new file mode 100644 index 0000000..bb57fd3 --- /dev/null +++ b/packages/web-ui/utils/get-super-admin-cookie-server.ts @@ -0,0 +1,10 @@ +import { cookies } from 'next/headers'; + +export function getSuperAdminCookieOnServer() { + const nextCookies = cookies(); + const adminCredentialsCookie = nextCookies.get('__admin'); + + return { + adminCredentialsCookie, + }; +} diff --git a/packages/web-ui/utils/get-url-path.ts b/packages/web-ui/utils/get-url-path.ts new file mode 100644 index 0000000..400dced --- /dev/null +++ b/packages/web-ui/utils/get-url-path.ts @@ -0,0 +1,10 @@ +import { headers } from 'next/headers'; + +export function getUrlPath() { + const { get: getHeader } = headers(); + const urlPath = getHeader('x-invoke-path'); + + return { + urlPath, + }; +}