Hi all, Been lurking for a bit trying to find an ...
# ory-network
g
Hi all, Been lurking for a bit trying to find an answer to an issue Iโ€™m having with CORS. Weโ€™re using Ory-Network, simple Password Login. Basically following: https://www.ory.sh/docs/getting-started/integrate-auth/nextjs to the letter. Works perfectly well for local development using the tunnel etc. The second I try to migrate to a custom domain, I get CORS issues left right and center. See attached image. Iโ€™ve got some slight code modifications where Iโ€™m wrapped everything in a Login Button control:
Copy code
import { useState, useEffect } from "react";
import { useRouter } from 'next/router';
import { Button } from "@mui/material";
import style from './LoginButton.module.css';
import ory from './Ory'


interface LoginButtonProps {
  onSignedIn?: (signedIn: boolean) => void;
}

function LoginButton(props: LoginButtonProps) {
  const router = useRouter();
  const [isLoggedIn, setIsLoggedIn] = useState(false);
  const [logoutUrl, setLogoutUrl] = useState<string>();


  function handleLogin() {
    
    ory.createBrowserLoginFlow().then((response) => {
      router.push(`${process.env.NEXT_PUBLIC_ORY_SDK_URL}/ui/login`);
    })
  }

  useEffect(() => {
    ory.toSession()
      .then((response) => {
        setIsLoggedIn(true);
        ory.createBrowserLogoutFlow().then(({ data }) => {
          setLogoutUrl(data.logout_url);
        });
      })
      .catch(() => {
        setIsLoggedIn(false);
      })
      .finally(() => {
        if (props.onSignedIn) {
          props.onSignedIn(isLoggedIn);
        }
      });
  }, [isLoggedIn, props]);

  if (!isLoggedIn)
    return <Button onClick={handleLogin} className={style.loginbuttonstyle}>Log In</Button>
  else
    return <></>

}

export default LoginButton;
with Ory.tsx containing:
Copy code
import { Configuration, FrontendApi } from "@ory/client";

const ory = new FrontendApi(
    new Configuration({
        basePath: process.env.NEXT_PUBLIC_ORY_SDK_URL,
        baseOptions: {
            withCredentials: true,
            
        },
    })
);

export default ory;
Ory is setup with the customer domain details in the second attached pic Final pic shows DNS settings inside of Vercel. Desperate to get this solved and would appreciate any help at all.
c
The CORS requests that are failing are targetting lff.website, the cname to ory is the subdomain, ie auth.lff.website. Update your front-end to target auth.lff.website and you should be golden ๐Ÿ‘
g
Thanks @curved-fountain-46946 Have updated DNS to look like this: Hopefully that works.
Exact same issue ๐Ÿ˜ž
c
Nono, I mean your ory client, it tries to talk to https://lff.website/sessions/whoami, however it should be talking to https://auth.lff.website/sessions/whoami - that's the value you need to update ๐Ÿ™‚
The DNS should be fine tbh
g
ahhhhhhhh
My brain is cooked (very late over here). Thanks. Will give that a shot.
c
No worries man! Btw, what tool did you use to blur your screenshot? Very practical ๐Ÿ˜„
g
So changed DNS back. Still same issue
Blur is courtesy of Clean Shot X. Best screencap tool Iโ€™ve ever used
๐Ÿ™Œ 1
c
Now the error message changed though, it looks like the request is failing in its entirety. Could you look in the network tab of the inspector in your browser when you make the request, and see why it fails?
Status code: (null) is typical when the DNS lookup fails, or you are getting connection refused, timeouts etc.
g
Good catch. Might be a DNS propogation problem. Bunch of NS Lookup failures.
c
Yeah, that's DNS for ya! Well, at least now you know where to troubleshoot ๐Ÿ˜„
g
Might be a good excuse to go to bed and let propagation happen over night ๐Ÿ˜ Thanks for all your help thus far - very much appreciated.
c
No worries, mate! Sleep tight!
b
Sorry to intervene your 1-1 here. We have issue with CORS and Ory Network as well. Was hoping to find someone who was able to solve them.
c
Oh, that's a 1? I had no idea - I'm sure JT is on top of the domain name ๐Ÿ˜Ž