mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-12 05:12:20 +00:00
single-object
This commit is contained in:
@@ -48,7 +48,7 @@ export default async function Page({
|
||||
}
|
||||
|
||||
async function loadSessionById(sessionId: string, organization?: string) {
|
||||
const recent = await getSessionCookieById(sessionId, organization);
|
||||
const recent = await getSessionCookieById({ sessionId, organization });
|
||||
return getSession(recent.id, recent.token).then((response) => {
|
||||
if (response?.session && response.session.factors?.user?.id) {
|
||||
return listAuthenticationMethodTypes(
|
||||
|
||||
@@ -31,10 +31,10 @@ export default async function Page({
|
||||
loginName?: string,
|
||||
organization?: string,
|
||||
) {
|
||||
const recent = await getMostRecentCookieWithLoginname(
|
||||
const recent = await getMostRecentCookieWithLoginname({
|
||||
loginName,
|
||||
organization,
|
||||
);
|
||||
});
|
||||
return getSession(recent.id, recent.token).then((response) => {
|
||||
if (response?.session && response.session.factors?.user?.id) {
|
||||
const userId = response.session.factors.user.id;
|
||||
@@ -58,7 +58,7 @@ export default async function Page({
|
||||
}
|
||||
|
||||
async function loadSessionById(sessionId: string, organization?: string) {
|
||||
const recent = await getSessionCookieById(sessionId, organization);
|
||||
const recent = await getSessionCookieById({ sessionId, organization });
|
||||
return getSession(recent.id, recent.token).then((response) => {
|
||||
if (response?.session && response.session.factors?.user?.id) {
|
||||
const userId = response.session.factors.user.id;
|
||||
|
||||
@@ -3,7 +3,6 @@ import Alert, { AlertType } from "@/ui/Alert";
|
||||
import DynamicTheme from "@/ui/DynamicTheme";
|
||||
import RegisterPasskey from "@/ui/RegisterPasskey";
|
||||
import UserAvatar from "@/ui/UserAvatar";
|
||||
import { getMostRecentCookieWithLoginname } from "@zitadel/next";
|
||||
import { loadMostRecentSession } from "@zitadel/next";
|
||||
|
||||
export default async function Page({
|
||||
|
||||
@@ -28,10 +28,10 @@ export default async function Page({
|
||||
loginName?: string,
|
||||
organization?: string,
|
||||
) {
|
||||
const recent = await getMostRecentCookieWithLoginname(
|
||||
const recent = await getMostRecentCookieWithLoginname({
|
||||
loginName,
|
||||
organization,
|
||||
);
|
||||
});
|
||||
return getSession(recent.id, recent.token).then((response) => {
|
||||
if (response?.session) {
|
||||
return response.session;
|
||||
@@ -40,7 +40,7 @@ export default async function Page({
|
||||
}
|
||||
|
||||
async function loadSessionById(sessionId: string, organization?: string) {
|
||||
const recent = await getSessionCookieById(sessionId, organization);
|
||||
const recent = await getSessionCookieById({ sessionId, organization });
|
||||
return getSession(recent.id, recent.token).then((response) => {
|
||||
if (response?.session) {
|
||||
return response.session;
|
||||
|
||||
@@ -7,7 +7,6 @@ import Alert from "@/ui/Alert";
|
||||
import DynamicTheme from "@/ui/DynamicTheme";
|
||||
import PasswordForm from "@/ui/PasswordForm";
|
||||
import UserAvatar from "@/ui/UserAvatar";
|
||||
import { getMostRecentCookieWithLoginname } from "@zitadel/next";
|
||||
import { loadMostRecentSession } from "@zitadel/next";
|
||||
|
||||
export default async function Page({
|
||||
|
||||
@@ -5,7 +5,7 @@ import { getMostRecentCookieWithLoginname } from "@zitadel/next";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
async function loadSession(loginName: string, authRequestId?: string) {
|
||||
const recent = await getMostRecentCookieWithLoginname(`${loginName}`);
|
||||
const recent = await getMostRecentCookieWithLoginname({ loginName });
|
||||
|
||||
if (authRequestId) {
|
||||
return createCallback({
|
||||
|
||||
@@ -31,10 +31,10 @@ export default async function Page({
|
||||
loginName?: string,
|
||||
organization?: string,
|
||||
) {
|
||||
const recent = await getMostRecentCookieWithLoginname(
|
||||
const recent = await getMostRecentCookieWithLoginname({
|
||||
loginName,
|
||||
organization,
|
||||
);
|
||||
});
|
||||
return getSession(recent.id, recent.token).then((response) => {
|
||||
if (response?.session) {
|
||||
return response.session;
|
||||
@@ -43,7 +43,7 @@ export default async function Page({
|
||||
}
|
||||
|
||||
async function loadSessionById(sessionId: string, organization?: string) {
|
||||
const recent = await getSessionCookieById(sessionId, organization);
|
||||
const recent = await getSessionCookieById({ sessionId, organization });
|
||||
return getSession(recent.id, recent.token).then((response) => {
|
||||
if (response?.session) {
|
||||
return response.session;
|
||||
|
||||
@@ -16,7 +16,7 @@ export async function POST(request: NextRequest) {
|
||||
body;
|
||||
|
||||
const recentPromise = sessionId
|
||||
? getSessionCookieById(sessionId).catch((error) => {
|
||||
? getSessionCookieById({ sessionId }).catch((error) => {
|
||||
return Promise.reject(error);
|
||||
})
|
||||
: loginName
|
||||
|
||||
@@ -11,7 +11,7 @@ export async function POST(request: NextRequest) {
|
||||
if (body) {
|
||||
const { sessionId } = body;
|
||||
|
||||
const sessionCookie = await getSessionCookieById(sessionId);
|
||||
const sessionCookie = await getSessionCookieById({ sessionId });
|
||||
|
||||
const session = await getSession(sessionCookie.id, sessionCookie.token);
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ export async function POST(request: NextRequest) {
|
||||
device.vendor || device.model ? ", " : ""
|
||||
}${os.name}${os.name ? ", " : ""}${browser.name}`;
|
||||
}
|
||||
const sessionCookie = await getSessionCookieById(sessionId);
|
||||
const sessionCookie = await getSessionCookieById({ sessionId });
|
||||
|
||||
const session = await getSession(sessionCookie.id, sessionCookie.token);
|
||||
|
||||
|
||||
@@ -165,9 +165,9 @@ export async function PUT(request: NextRequest) {
|
||||
*/
|
||||
export async function DELETE(request: NextRequest) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const id = searchParams.get("id");
|
||||
if (id) {
|
||||
const session = await getSessionCookieById(id);
|
||||
const sessionId = searchParams.get("id");
|
||||
if (sessionId) {
|
||||
const session = await getSessionCookieById({ sessionId });
|
||||
|
||||
return deleteSession(session.id, session.token)
|
||||
.then(() => {
|
||||
|
||||
@@ -12,7 +12,7 @@ export async function POST(request: NextRequest) {
|
||||
if (body) {
|
||||
const { sessionId } = body;
|
||||
|
||||
const sessionCookie = await getSessionCookieById(sessionId);
|
||||
const sessionCookie = await getSessionCookieById({ sessionId });
|
||||
|
||||
const session = await getSession(sessionCookie.id, sessionCookie.token);
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ export async function POST(request: NextRequest) {
|
||||
device.vendor || device.model ? ", " : ""
|
||||
}${os.name}${os.name ? ", " : ""}${browser.name}`;
|
||||
}
|
||||
const sessionCookie = await getSessionCookieById(sessionId);
|
||||
const sessionCookie = await getSessionCookieById({ sessionId });
|
||||
|
||||
const session = await getSession(sessionCookie.id, sessionCookie.token);
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ export async function verifyTOTP(
|
||||
loginName?: string,
|
||||
organization?: string,
|
||||
) {
|
||||
return getMostRecentCookieWithLoginname(loginName, organization)
|
||||
return getMostRecentCookieWithLoginname({ loginName, organization })
|
||||
.then((recent) => {
|
||||
return getSession(recent.id, recent.token).then((response) => {
|
||||
return { session: response?.session, token: recent.token };
|
||||
|
||||
@@ -111,10 +111,10 @@ export async function getMostRecentSessionCookie<T>(): Promise<any> {
|
||||
}
|
||||
|
||||
export async function getSessionCookieById<T>({
|
||||
id,
|
||||
sessionId,
|
||||
organization,
|
||||
}: {
|
||||
id: string;
|
||||
sessionId: string;
|
||||
organization?: string;
|
||||
}): Promise<SessionCookie<T>> {
|
||||
const cookiesList = cookies();
|
||||
@@ -123,7 +123,9 @@ export async function getSessionCookieById<T>({
|
||||
if (stringifiedCookie?.value) {
|
||||
const sessions: SessionCookie<T>[] = JSON.parse(stringifiedCookie?.value);
|
||||
|
||||
const found = sessions.find((s) => (organization ? s.organization === organization && s.id === id : s.id === id));
|
||||
const found = sessions.find((s) =>
|
||||
organization ? s.organization === organization && s.id === sessionId : s.id === sessionId,
|
||||
);
|
||||
if (found) {
|
||||
return found;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user