mirror of
https://github.com/zitadel/zitadel.git
synced 2025-12-12 05:12:20 +00:00
fix search params
This commit is contained in:
@@ -4,17 +4,22 @@ import UserAvatar from "#/ui/UserAvatar";
|
|||||||
import { getMostRecentCookieWithLoginname } from "#/utils/cookies";
|
import { getMostRecentCookieWithLoginname } from "#/utils/cookies";
|
||||||
|
|
||||||
async function loadSession(loginName: string) {
|
async function loadSession(loginName: string) {
|
||||||
const recent = await getMostRecentCookieWithLoginname(loginName);
|
try {
|
||||||
|
const recent = await getMostRecentCookieWithLoginname(`${loginName}`);
|
||||||
|
|
||||||
return getSession(server, recent.id, recent.token).then(({ session }) => {
|
return getSession(server, recent.id, recent.token).then(({ session }) => {
|
||||||
console.log("ss", session);
|
console.log("ss", session);
|
||||||
return session;
|
return session;
|
||||||
});
|
});
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error("Session could not be loaded!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function Page({ searchParams }: { searchParams: any }) {
|
export default async function Page({ searchParams }: { searchParams: any }) {
|
||||||
const { loginName } = searchParams;
|
const { loginName } = searchParams;
|
||||||
|
|
||||||
|
console.log(loginName);
|
||||||
const sessionFactors = await loadSession(loginName);
|
const sessionFactors = await loadSession(loginName);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { createSession, getSession, server, setSession } from "#/lib/zitadel";
|
|||||||
import {
|
import {
|
||||||
SessionCookie,
|
SessionCookie,
|
||||||
addSessionToCookie,
|
addSessionToCookie,
|
||||||
getMostRecentCookieWithLoginname,
|
|
||||||
getMostRecentSessionCookie,
|
getMostRecentSessionCookie,
|
||||||
updateSessionCookie,
|
updateSessionCookie,
|
||||||
} from "#/utils/cookies";
|
} from "#/utils/cookies";
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ export function addHumanUser(
|
|||||||
return mgmt
|
return mgmt
|
||||||
.addHumanUser(
|
.addHumanUser(
|
||||||
{
|
{
|
||||||
email: { email, isVerified: false },
|
email: { email },
|
||||||
username: email,
|
username: email,
|
||||||
profile: { firstName, lastName },
|
profile: { firstName, lastName },
|
||||||
password: { password },
|
password: { password },
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ export default function RegisterForm({
|
|||||||
|
|
||||||
function submitAndLink(value: Inputs): Promise<boolean | void> {
|
function submitAndLink(value: Inputs): Promise<boolean | void> {
|
||||||
return submitRegister(value).then((resp: any) => {
|
return submitRegister(value).then((resp: any) => {
|
||||||
return router.push(`/register/success?userid=${resp.userId}`);
|
return router.push(`/verify?userID=${resp.userId}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,10 @@ export default function UsernameForm() {
|
|||||||
function submitUsernameAndContinue(value: Inputs): Promise<boolean | void> {
|
function submitUsernameAndContinue(value: Inputs): Promise<boolean | void> {
|
||||||
return submitUsername(value).then(({ factors }) => {
|
return submitUsername(value).then(({ factors }) => {
|
||||||
console.log(factors);
|
console.log(factors);
|
||||||
return router.push(`/password?loginName=${factors.user.loginName}`);
|
return router.push(
|
||||||
|
`/password?` +
|
||||||
|
new URLSearchParams({ loginName: `${factors.user.loginName}` })
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ export default function VerifyEmailForm({ userId }: Props) {
|
|||||||
|
|
||||||
async function submitCode(values: Inputs) {
|
async function submitCode(values: Inputs) {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
const res = await fetch("/email/verify", {
|
const res = await fetch("/verifyemail", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|||||||
@@ -146,16 +146,27 @@ export async function getMostRecentCookieWithLoginname(
|
|||||||
if (stringifiedCookie?.value) {
|
if (stringifiedCookie?.value) {
|
||||||
const sessions: SessionCookie[] = JSON.parse(stringifiedCookie?.value);
|
const sessions: SessionCookie[] = JSON.parse(stringifiedCookie?.value);
|
||||||
|
|
||||||
const latest = sessions
|
console.log("sess", sessions);
|
||||||
.filter((cookie) => (loginName ? cookie.loginName === loginName : true))
|
const filtered = sessions.filter((cookie) => {
|
||||||
.reduce((prev, current) => {
|
console.log("filtered", `${cookie.loginName}`, loginName?.toString());
|
||||||
return new Date(prev.changeDate).getTime() >
|
return !!loginName ? cookie.loginName === loginName : true;
|
||||||
new Date(current.changeDate).getTime()
|
});
|
||||||
? prev
|
|
||||||
: current;
|
|
||||||
});
|
|
||||||
|
|
||||||
return latest;
|
const latest =
|
||||||
|
filtered && filtered.length
|
||||||
|
? filtered.reduce((prev, current) => {
|
||||||
|
return new Date(prev.changeDate).getTime() >
|
||||||
|
new Date(current.changeDate).getTime()
|
||||||
|
? prev
|
||||||
|
: current;
|
||||||
|
})
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
if (latest) {
|
||||||
|
return latest;
|
||||||
|
} else {
|
||||||
|
return Promise.reject();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return Promise.reject();
|
return Promise.reject();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user