create session with password on register

This commit is contained in:
Max Peintner
2023-06-16 15:08:41 +02:00
parent fbbc48e5cd
commit 3aa8e8fbc4
7 changed files with 47 additions and 15 deletions

View File

@@ -22,7 +22,6 @@ export default async function Page({
});
}
console.log(sessionFactors);
return (
<div className="flex flex-col items-center space-y-4">
<h1>Use your passkey to confirm its really you</h1>

View File

@@ -18,9 +18,9 @@ import { NextRequest, NextResponse } from "next/server";
export async function POST(request: NextRequest) {
const body = await request.json();
if (body) {
const { loginName } = body;
const { loginName, password } = body;
const createdSession = await createSession(server, loginName);
const createdSession = await createSession(server, loginName, password);
if (createdSession) {
return getSession(
server,

View File

@@ -83,10 +83,16 @@ export async function getPasswordComplexitySettings(
export async function createSession(
server: ZitadelServer,
loginName: string
loginName: string,
password?: string
): Promise<CreateSessionResponse | undefined> {
const sessionService = session.getSession(server);
return sessionService.createSession({ checks: { user: { loginName } } }, {});
return password
? sessionService.createSession(
{ checks: { user: { loginName } }, password: { password } },
{}
)
: sessionService.createSession({ checks: { user: { loginName } } }, {});
}
export async function setSession(

View File

@@ -41,7 +41,7 @@ export default function AuthenticationMethodRadio({
? "bg-background-light-400 dark:bg-background-dark-400"
: "bg-background-light-400 dark:bg-background-dark-400"
}
relative border boder-divider-light dark:border-divider-dark flex cursor-pointer rounded-lg px-5 py-4 focus:outline-none hover:shadow-md`
relative border boder-divider-light dark:border-divider-dark flex cursor-pointer rounded-lg px-5 py-4 focus:outline-none hover:shadow-lg dark:hover:bg-white/10`
}
>
{({ active, checked }) => (

View File

@@ -141,7 +141,11 @@ export default function RegisterFormWithoutPassword({ legal }: Props) {
/>
)}
<div className="py-4">
<p className="mt-4 ztdl-p mb-6 block text-text-light-secondary-500 dark:text-text-dark-secondary-500">
Select the method you would like to authenticate
</p>
<div className="pb-4">
<AuthenticationMethodRadio
selected={selected}
selectionChanged={setSelected}

View File

@@ -13,7 +13,7 @@ export default function SessionsList({ sessions }: Props) {
const [list, setList] = useState<Session[]>(sessions);
return sessions ? (
<div className="flex flex-col">
<div className="flex flex-col space-y-2">
{list
.filter((session) => session?.factors?.user?.loginName)
.map((session, index) => {

View File

@@ -1,14 +1,10 @@
"use client";
import {
LegalAndSupportSettings,
PasswordComplexitySettings,
} from "@zitadel/server";
import { PasswordComplexitySettings } from "@zitadel/server";
import PasswordComplexity from "./PasswordComplexity";
import { useState } from "react";
import { Button, ButtonVariants } from "./Button";
import { TextInput } from "./Input";
import { PrivacyPolicyCheckboxes } from "./PrivacyPolicyCheckboxes";
import { FieldValues, useForm } from "react-hook-form";
import {
lowerCaseValidator,
@@ -71,9 +67,36 @@ export default function SetPasswordForm({
return res.json();
}
async function createSessionWithLoginNameAndPassword(
loginName: string,
password: string
) {
setLoading(true);
const res = await fetch("/session", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
loginName: loginName,
password: password,
}),
});
setLoading(false);
if (!res.ok) {
throw new Error("Failed to set user");
}
return res.json();
}
function submitAndLink(value: Inputs): Promise<boolean | void> {
return submitRegister(value).then((resp: any) => {
return router.push(`/verify?userID=${resp.userId}`);
return submitRegister(value).then((humanResponse: any) => {
return createSessionWithLoginNameAndPassword(email, value.password).then(
() => {
return router.push(`/verify?userID=${humanResponse.userId}`);
}
);
});
}