fix
This commit is contained in:
@@ -92,7 +92,7 @@ export async function SessionLogin(
|
||||
|
||||
if (data.redirect_url) return { success: true, redirectURL: data.redirect_url };
|
||||
return { success: true };
|
||||
} catch {
|
||||
} catch (error) {
|
||||
return { success: false, message: t("serverError") };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ export async function getConsents() {
|
||||
if (!response.ok) return []
|
||||
|
||||
const consents = await response.json() as Consent[]
|
||||
consents.forEach((consent: Consent) => {
|
||||
consents?.forEach((consent: Consent) => {
|
||||
consent.isRevokable = consent.client_id !== process.env.CLIENT_ID
|
||||
})
|
||||
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
"use server"
|
||||
|
||||
import type { Position } from "@/types"
|
||||
import { cookies } from "next/headers"
|
||||
|
||||
export async function getMyPositions(): Promise<Position[]> {
|
||||
const store = await cookies()
|
||||
const accessToken = store.get("access_token")?.value
|
||||
if (!accessToken) return []
|
||||
|
||||
const response = await fetch(
|
||||
`${process.env.KOTOSOFT_ID_API_URL}/api/v1/me/positions`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
},
|
||||
cache: "no-store",
|
||||
}
|
||||
)
|
||||
|
||||
if (!response.ok) return []
|
||||
return (await response.json()) as Position[]
|
||||
}
|
||||
|
||||
export async function listAllPositions(): Promise<Position[] | null> {
|
||||
const store = await cookies()
|
||||
const accessToken = store.get("access_token")?.value
|
||||
if (!accessToken) return null
|
||||
|
||||
const response = await fetch(
|
||||
`${process.env.KOTOSOFT_ID_API_URL}/api/v1/admin/positions`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
},
|
||||
cache: "no-store",
|
||||
}
|
||||
)
|
||||
|
||||
if (response.status === 403) return null
|
||||
if (!response.ok) return null
|
||||
return (await response.json()) as Position[]
|
||||
}
|
||||
|
||||
export async function upsertPosition(code: string, name: string, description?: string | null): Promise<{ success: boolean }> {
|
||||
const store = await cookies()
|
||||
const accessToken = store.get("access_token")?.value
|
||||
if (!accessToken) return { success: false }
|
||||
|
||||
const response = await fetch(
|
||||
`${process.env.KOTOSOFT_ID_API_URL}/api/v1/admin/positions`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({ code, name, ...(description ? { description } : {}) }),
|
||||
}
|
||||
)
|
||||
|
||||
if (!response.ok) {
|
||||
return { success: false }
|
||||
}
|
||||
|
||||
return { success: true }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user