full-notebook-65880
09/17/2024, 12:01 PMbrief-egg-61061
09/17/2024, 12:01 PMbrief-egg-61061
09/17/2024, 12:02 PMreturn_toreturn_totsx frontend     .createBrowserLoginFlow({       returnTo: returnTo || "/", // redirect to the root path after login       // if the user has a session, refresh it       refresh: true,       // if the aal2 query parameter is set, we get the two factor login flow UI nodes       aal: aal2 ? "aal2" : "aal1",     })     .then(({ data: flow }) => {       // set the flow data       setFlow(flow)     })     .catch((err) => {       // Couldn't create login flow       // handle the error     })return_toreturn_toreturn_toreturn_toreturn_toreturn_toflow.return_totsx sdk.getLoginFlow({ id: flow }).then(({ data: flow }) => {     const returnTo = flow.return_to     return sdk.createBrowserRegistrationFlow({       id: flow.id,       return_to: returnTo,     })   })full-notebook-65880
09/17/2024, 12:23 PMsdk.getLoginFlow({ id: flow }).then(({ data: flow }) => {  
  const returnTo = flow.return_to  
  return sdk.createBrowserRegistrationFlow({  
    id: flow.id,  
    return_to: returnTo,  
  })  
})brief-egg-61061
09/17/2024, 12:23 PMbrief-egg-61061
09/17/2024, 12:24 PMreturn_tologin.tsxregistration.tsxtsx // login.tsx import { useEffect } from "react" import { FrontendApi } from "@ory/client"  const frontend = new FrontendApi(/* your configuration here */)  export const Login = () => {   // ... your other login code here ...    const switchToRegistration = (flowId) => {     frontend.getLoginFlow({ id: flowId }).then(({ data: flow }) => {       const returnTo = flow.return_to       return frontend.createBrowserRegistrationFlow({         id: flow.id,         return_to: returnTo,       })     })   }    // Call switchToRegistration when the user decides to switch to registration   // For example, you might call it in a button click handler }FrontendApifull-notebook-65880
09/17/2024, 12:28 PMimport {LoginFlow, UpdateLoginFlowBody} from "@ory/client"
import {AxiosError} from "axios"
import type {NextPage} from "next"
import Link from "next/link"
import {useRouter} from "next/router"
import React, {useEffect, useState} from "react"
import {LogoutLink, Flow, Values} from "@/pkg"
import {handleGetFlowError, handleFlowError} from "@/pkg/errors"
import ory from "@/pkg/sdk"
import {Button} from "@ui/button";
import PageHead from "@ui/PageHead/PageHead";
import AuthBanner from "@components/AuthBanner/AuthBanner";
import LoginSkeleton from "@ui/Skeletons/PageSkeletons/AuthSkeleton/LoginSkeleton";
const Login: NextPage = () => {
    const [flow, setFlow] = useState<LoginFlow>()
    // Get ?flow=... from the URL
    const router = useRouter()
    const {
        return_to: returnTo,
        flow: flowId,
        // Refresh means we want to refresh the session. This is needed, for example, when we want to update the password
        // of a user.
        refresh,
        // AAL = Authorization Assurance Level. This implies that we want to upgrade the AAL, meaning that we want
        // to perform two-factor authentication/verification.
        aal,
    } = router.query
    // This might be confusing, but we want to show the user an option
    // to sign out if they are performing two-factor authentication!
    const onLogout = LogoutLink([aal, refresh])
    useEffect(() => {
        // If the router is not ready yet, or we already have a flow, do nothing.
        if (!router.isReady || flow) {
            return
        }
        // If ?flow=.. was in the URL, we fetch it
        if (flowId) {
            ory
                .getLoginFlow({id: String(flowId)})
                .then(({data}) => {
                    setFlow(data)
                })
                .catch(handleGetFlowError(router, "login", setFlow))
            return
        }
        // Otherwise we initialize it
        ory
            .createBrowserLoginFlow({
                refresh: Boolean(refresh),
                aal: aal ? String(aal) : undefined,
                returnTo: returnTo ? String(returnTo) : undefined,
            })
            .then(({data}) => {
                setFlow(data)
            })
            .catch(handleFlowError(router, "login", setFlow))
    }, [flowId, router, router.isReady, aal, refresh, returnTo, flow])
    // const onSubmit = (values: UpdateLoginFlowBody) =>
    const onSubmit = (values: Partial<Values>): Promise<void> =>
        router
            // On submission, add the flow ID to the URL but do not navigate. This prevents the user loosing
            // his data when she/he reloads the page.
            .push(`/auth/login?flow=${flow?.id}`, undefined, {shallow: true})
            .then(() =>
                ory
                    .updateLoginFlow({
                        flow: String(flow?.id),
                        updateLoginFlowBody: values as UpdateLoginFlowBody,
                    })
                    // We logged in successfully! Let's bring the user home.
                    .then(() => {
                        if (flow?.return_to) {
                            window.location.href = flow?.return_to
                            return
                        }
                        router.push("/")
                    })
                    .then(() => {
                    })
                    .catch(handleFlowError(router, "login", setFlow))
                    .catch((err: AxiosError) => {
                        // If the previous handler did not catch the error it's most likely a form validation error
                        if (err.response?.status === 400) {
                            // Yup, it is!
                            // @ts-ignore
                            setFlow(err.response?.data)
                            return
                        }
                        return Promise.reject(err)
                    }),
            )
    return (
        <div className={"max-md:tw-h-screen tw-grid tw-grid-cols-5 lg:tw-grid-cols-12 lg:tw-gap-6 tw-bg-mvnGray-25"}>
            <PageHead title={"Sign In"}/>
            <div className="max-md:tw-hidden tw-col-span-7">
                <AuthBanner/>
            </div>
            <div
                className="tw-col-span-12 lg:tw-col-span-5 tw-px-4 tw-py-6 md:tw-pl-10 lg:tw-pr-[64px] tw-flex tw-items-center tw-justify-center">
                {!flow ?
                    <LoginSkeleton/>
                    :
                    <div className={"tw-w-full tw-h-full"}>
                        <div>
                            <Link href={"/"}>
                                <figure className="tw-flex tw-items-center tw-justify-center">
                                    <img src="/assets/globalAssets/moveOnLogo.svg" alt="moveon"/>
                                </figure>
                            </Link>
                            <div className="tw-text-center tw-py-8 tw-space-y-3">
                                <h2 className="tw-text-[30px] tw-font-bold">
                                    {(() => {
                                        if (flow?.refresh) {
                                            return "Confirm Action"
                                        } else if (flow?.requested_aal === "aal2") {
                                            return "Two-Factor Authentication"
                                        }
                                        return "Sign In"
                                    })()}
                                </h2>
                                <p className="tw-text-mvnBlack-100">Welcome back! Log in to your account </p>
                            </div>
                            <Flow onSubmit={onSubmit} flow={flow}/>
                        </div>
                        {aal || refresh ? (
                            <div>
                                <Button data-testid="logout-link" onClick={onLogout} className="tw-w-full">
                                    Log out
                                </Button>
                            </div>
                        ) : (
                            <>
                                <div className="tw-flex tw-items-center tw-justify-center tw-gap-4 tw-pt-1">
                                    New here?
                                    <Link href="/auth/registration" passHref
                                          className="tw-font-bold tw-text-mvnGreen-800 hover:tw-no-underline hover:tw-text-mvnGreen-950">
                                        Sign up
                                    </Link>
                                </div>
                            </>
                        )}
                    </div>
                }
            </div>
        </div>
    )
}
export default Loginbrief-egg-61061
09/17/2024, 12:28 PMbrief-egg-61061
09/17/2024, 12:28 PMfull-notebook-65880
09/17/2024, 12:38 PMconst switchToRegistration = (flowId: string) => {
    ory.getLoginFlow({id: flowId}).then(({data: flow}) => {
        const returnTo = flow.return_to
        return ory.createBrowserRegistrationFlow({
            id: flow.id,
            return_to: returnTo,
        })
    })
}
from : return ory.createBrowserRegistrationFlow({
            id: flow.id,brief-egg-61061
09/17/2024, 12:38 PMbrief-egg-61061
09/17/2024, 12:39 PMcreateBrowserRegistrationFlowidFrontendApiCreateBrowserRegistrationFlowRequestidcreateBrowserRegistrationFlowididtsx const switchToRegistration = (flowId: string) => {   ory.getLoginFlow({id: flowId}).then(({data: flow}) => {     const returnTo = flow.return_to     return ory.createBrowserRegistrationFlow({       return_to: returnTo,     })   }) }createBrowserRegistrationFlowreturn_toididfull-notebook-65880
10/30/2024, 9:30 AMbrief-egg-61061
10/30/2024, 9:30 AMbrief-egg-61061
10/30/2024, 9:30 AMrefresh=truetsx import { FrontendApi, Configuration } from "@ory/client"  const frontend = new FrontendApi(   new Configuration({     basePath: process.env.NEXT_PUBLIC_ORY_SDK_URL,     baseOptions: {       withCredentials: true,     },   }) )  const refreshLogin = () => {   frontend     .createBrowserLoginFlow({       refresh: true, // This forces a session refresh       returnTo: "/dashboard", // Redirect to dashboard after login     })     .then(({ data: flow }) => {       // Handle the flow data       setFlow(flow)     })     .catch((err) => {       // Handle any errors       console.error("Error creating login flow:", err)     }) }refreshLoginrefresh: truecreateBrowserLoginFlowreturnTo@ory/integrationsfull-notebook-65880
01/06/2025, 9:16 AMbrief-egg-61061
01/06/2025, 9:16 AMbrief-egg-61061
01/06/2025, 9:16 AM{your-ory-backend-url}ory tunnel --dev <http://localhost:3000> {your-ory-backend-url}--devtsx import { Configuration, FrontendApi } from "@ory/client"  const frontend = new FrontendApi(   new Configuration({     basePath: "<http://localhost:4000>",     baseOptions: {       withCredentials: true,     },   }) )frontendtsx frontend.createBrowserLoginFlow()   .then(({ data: flow }) => {     // Handle the flow data     setFlow(flow)   })   .catch((err) => {     // Handle any errors     console.error("Error creating login flow:", err)   })full-notebook-65880
01/06/2025, 9:20 AMbrief-egg-61061
01/06/2025, 9:20 AMbrief-egg-61061
01/06/2025, 9:20 AMory tunneltypescript import { Configuration, FrontendApi } from "@ory/client"  const ory = new FrontendApi(   new Configuration({     basePath: "<https://admin.auth.service.staging.global.baharcart.com>",     baseOptions: {       withCredentials: true,     },   }) )kratos.ymlyaml serve:   public:     cors:       enabled: true       allowed_origins:         - <http://localhost:5173>       allowed_methods:         - POST         - GET         - PUT         - PATCH         - DELETE       allowed_headers:         - Authorization         - Content-Type       exposed_headers:         - Content-Type       allow_credentials: true       debug: trueorytypescript ory.createBrowserLoginFlow()   .then(({ data: flow }) => {     // Handle the flow data     setFlow(flow)   })   .catch((err) => {     // Handle any errors     console.error("Error creating login flow:", err)   })<http://localhost:5173><https://admin.auth.service.staging.global.baharcart.com>basePathfull-notebook-65880
01/12/2025, 5:06 AMbrief-egg-61061
01/12/2025, 5:06 AMbrief-egg-61061
01/12/2025, 5:06 AMyaml courier:   channels:     - id: sms       type: http       request_config:         url: <https://api.your-sms-provider.com/send-sms>         method: POST         body: <base64://ZnVuY3Rpb24oY3R4KSB7CiAgVG86IGN0eC5yZWNpcGllbnQsCiAgQm9keTogY3R4LmJvZHksCn0>=         headers:           Content-Type: application/json         auth:           type: basic_auth           config:             user: your-username             password: your-passwordbodyjsonnet function(ctx) {   To: ctx.recipient,   Body: ctx.body, }yaml selfservice:   methods:     code:       passwordless_enabled: truejson {   "properties": {     "traits": {       "type": "object",       "properties": {         "phone": {           "type": "string",           "format": "tel",           "title": "Phone number",           "<http://ory.sh/kratos|ory.sh/kratos>": {             "credentials": {               "code": {                 "identifier": true,                 "via": "sms"               }             },             "verification": {               "via": "sms"             }           }         }       }     }   } }<https://api.your-sms-provider.com/send-sms>your-usernameyour-password