From 5a2abe0c2f3fe73f9853100629b33f571bc0dce7 Mon Sep 17 00:00:00 2001 From: miran248 Date: Wed, 30 Aug 2023 20:41:55 +0200 Subject: [PATCH] feat: extract kratos api into services folder --- src/website/app/forms/SubmitButton.tsx | 2 +- src/website/app/layout/FieldError.tsx | 2 +- src/website/app/layout/FormField.tsx | 2 +- src/website/app/layout/ServerMessage.tsx | 24 +- src/website/app/openapi/kratos.ts | 3 +- src/website/app/ory.server.tsx | 87 --- src/website/app/routes/_index.tsx | 100 +-- src/website/app/routes/api.webhooks.oidc.$.ts | 4 - src/website/app/routes/change-password.tsx | 277 +++---- .../app/routes/index/CurrentSession.tsx | 2 +- .../app/routes/index/OtherSessions.tsx | 2 +- src/website/app/routes/login.tsx | 711 +++-------------- .../app/routes/login/PasswordLogin.tsx | 16 - src/website/app/routes/login/SocialLogin.tsx | 16 - src/website/app/routes/logout.tsx | 18 +- src/website/app/routes/register.tsx | 719 +++--------------- .../app/routes/register/PasswordRegister.tsx | 16 - .../app/routes/register/SocialRegister.tsx | 16 - .../app/routes/social/SocialButtons.tsx | 16 +- src/website/app/services/kratos/client.ts | 6 + .../services/kratos/createNativeLoginFlow.ts | 54 ++ .../kratos/createNativeRecoveryFlow.ts | 45 ++ .../kratos/createNativeRegistrationFlow.ts | 54 ++ .../app/services/kratos/disableMySession.ts | 43 ++ .../app/services/kratos/disableSession.ts | 39 + .../services/kratos/exchangeSessionToken.ts | 50 ++ .../app/services/kratos/getIdentity.ts | 29 + .../app/services/kratos/getLoginFlow.ts | 34 + .../app/services/kratos/getRecoveryFlow.ts | 42 + .../services/kratos/getRegistrationFlow.ts | 44 ++ .../app/services/kratos/listIdentities.ts | 33 + .../services/kratos/listIdentitySessions.ts | 39 + .../app/services/kratos/listMySessions.ts | 33 + .../services/kratos/performNativeLogout.ts | 44 ++ src/website/app/services/kratos/toSession.ts | 32 + .../app/services/kratos/updateLoginFlow.ts | 117 +++ .../app/services/kratos/updateRecoveryFlow.ts | 98 +++ .../services/kratos/updateRegistrationFlow.ts | 117 +++ src/website/app/session.server.ts | 2 +- .../app/unused-routes/admin.$userId.tsx | 65 +- .../app/unused-routes/admin._index.tsx | 11 +- src/website/app/utils.ts | 58 +- src/website/package-lock.json | 32 +- src/website/package.json | 4 +- src/website/tsconfig.json | 20 +- 45 files changed, 1405 insertions(+), 1773 deletions(-) delete mode 100644 src/website/app/ory.server.tsx create mode 100644 src/website/app/services/kratos/client.ts create mode 100644 src/website/app/services/kratos/createNativeLoginFlow.ts create mode 100644 src/website/app/services/kratos/createNativeRecoveryFlow.ts create mode 100644 src/website/app/services/kratos/createNativeRegistrationFlow.ts create mode 100644 src/website/app/services/kratos/disableMySession.ts create mode 100644 src/website/app/services/kratos/disableSession.ts create mode 100644 src/website/app/services/kratos/exchangeSessionToken.ts create mode 100644 src/website/app/services/kratos/getIdentity.ts create mode 100644 src/website/app/services/kratos/getLoginFlow.ts create mode 100644 src/website/app/services/kratos/getRecoveryFlow.ts create mode 100644 src/website/app/services/kratos/getRegistrationFlow.ts create mode 100644 src/website/app/services/kratos/listIdentities.ts create mode 100644 src/website/app/services/kratos/listIdentitySessions.ts create mode 100644 src/website/app/services/kratos/listMySessions.ts create mode 100644 src/website/app/services/kratos/performNativeLogout.ts create mode 100644 src/website/app/services/kratos/toSession.ts create mode 100644 src/website/app/services/kratos/updateLoginFlow.ts create mode 100644 src/website/app/services/kratos/updateRecoveryFlow.ts create mode 100644 src/website/app/services/kratos/updateRegistrationFlow.ts diff --git a/src/website/app/forms/SubmitButton.tsx b/src/website/app/forms/SubmitButton.tsx index 32e9829..8a01ac3 100644 --- a/src/website/app/forms/SubmitButton.tsx +++ b/src/website/app/forms/SubmitButton.tsx @@ -11,7 +11,7 @@ export const SubmitButton: FC< disabled={disabled} className={join( "flex w-full justify-center rounded-md bg-slate-500 hover:bg-slate-900 px-3 py-1.5 text-sm font-semibold leading-6 text-white shadow-sm focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-slate-600 transition", - disabled ? "opacity-50" : "" + disabled ? "pointer-events-none opacity-50" : "" )} > {children} diff --git a/src/website/app/layout/FieldError.tsx b/src/website/app/layout/FieldError.tsx index 84476f4..784cd3b 100644 --- a/src/website/app/layout/FieldError.tsx +++ b/src/website/app/layout/FieldError.tsx @@ -7,7 +7,7 @@ export const FieldError: FC<{ name: string }> = ({ name }) => { if ( data === undefined || - data.state !== "not-valid" || + data.type !== "not-valid" || name in data.messages === false ) { return null; diff --git a/src/website/app/layout/FormField.tsx b/src/website/app/layout/FormField.tsx index 58850f1..8f00fa1 100644 --- a/src/website/app/layout/FormField.tsx +++ b/src/website/app/layout/FormField.tsx @@ -25,7 +25,7 @@ export const FormField: FC<{ disabled={disabled} className={join( "sm:col-span-2 sm:h-10 sm:mt-0 sm:text-sm focus:ring-slate-500 focus:border-slate-500 bg-white border-2 border-slate-300 col-span-3 mt-1 px-2 rounded-md", - disabled ? "opacity-50" : "" + disabled ? "pointer-events-none opacity-50" : "" )} /> diff --git a/src/website/app/layout/ServerMessage.tsx b/src/website/app/layout/ServerMessage.tsx index 2dbae09..b801478 100644 --- a/src/website/app/layout/ServerMessage.tsx +++ b/src/website/app/layout/ServerMessage.tsx @@ -1,4 +1,8 @@ -import { CheckCircleIcon, XCircleIcon } from "@heroicons/react/20/solid"; +import { + CheckCircleIcon, + InformationCircleIcon, + XCircleIcon, +} from "@heroicons/react/20/solid"; import { FC } from "react"; import { useFetcherData } from "~/hooks/useFetcherContext"; @@ -11,7 +15,7 @@ export const ServerMessage: FC = () => { console.log("ServerMessage data", data); - if (data.state === "success") { + if (data.type === "success") { return (
{
); } - if (data.state === "failure") { + if (data.type === "info") { + return ( +
+
+ ); + } + if (data.type === "failure") { return (
); const SocialButton: FC< - PropsWithChildren & { type: string; className?: string } -> = ({ type, className, children }) => ( + PropsWithChildren & { type: string; disabled?: boolean; className?: string } +> = ({ type, disabled = false, className, children }) => (