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