mirror of
				https://github.com/steveiliop56/tinyauth.git
				synced 2025-11-04 08:05:42 +00:00 
			
		
		
		
	refactor: handle url queries null values better
This commit is contained in:
		@@ -8,7 +8,7 @@ import { ReactNode } from "react";
 | 
				
			|||||||
export const ContinuePage = () => {
 | 
					export const ContinuePage = () => {
 | 
				
			||||||
  const queryString = window.location.search;
 | 
					  const queryString = window.location.search;
 | 
				
			||||||
  const params = new URLSearchParams(queryString);
 | 
					  const params = new URLSearchParams(queryString);
 | 
				
			||||||
  const redirectUri = params.get("redirect_uri");
 | 
					  const redirectUri = params.get("redirect_uri") ?? "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const { isLoggedIn, disableContinue } = useUserContext();
 | 
					  const { isLoggedIn, disableContinue } = useUserContext();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -16,7 +16,7 @@ export const ContinuePage = () => {
 | 
				
			|||||||
    return <Navigate to={`/login?redirect_uri=${redirectUri}`} />;
 | 
					    return <Navigate to={`/login?redirect_uri=${redirectUri}`} />;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (redirectUri === "null") {
 | 
					  if (redirectUri === "null" || redirectUri === "") {
 | 
				
			||||||
    return <Navigate to="/" />;
 | 
					    return <Navigate to="/" />;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -27,15 +27,29 @@ export const ContinuePage = () => {
 | 
				
			|||||||
      color: "blue",
 | 
					      color: "blue",
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
    setTimeout(() => {
 | 
					    setTimeout(() => {
 | 
				
			||||||
      window.location.href = redirectUri!;
 | 
					      window.location.href = redirectUri;
 | 
				
			||||||
    }, 500);
 | 
					    }, 500);
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const urlParsed = URL.parse(redirectUri!);
 | 
					  const urlParsed = URL.parse(redirectUri);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (urlParsed === null) {
 | 
				
			||||||
 | 
					    return (
 | 
				
			||||||
 | 
					      <ContinuePageLayout>
 | 
				
			||||||
 | 
					        <Text size="xl" fw={700}>
 | 
				
			||||||
 | 
					          Invalid Redirect
 | 
				
			||||||
 | 
					        </Text>
 | 
				
			||||||
 | 
					        <Text>
 | 
				
			||||||
 | 
					          The redirect URL is invalid, please contact the app owner to fix the
 | 
				
			||||||
 | 
					          issue.
 | 
				
			||||||
 | 
					        </Text>
 | 
				
			||||||
 | 
					      </ContinuePageLayout>
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (
 | 
					  if (
 | 
				
			||||||
    window.location.protocol === "https:" &&
 | 
					    window.location.protocol === "https:" &&
 | 
				
			||||||
    urlParsed!.protocol === "http:"
 | 
					    urlParsed.protocol === "http:"
 | 
				
			||||||
  ) {
 | 
					  ) {
 | 
				
			||||||
    return (
 | 
					    return (
 | 
				
			||||||
      <ContinuePageLayout>
 | 
					      <ContinuePageLayout>
 | 
				
			||||||
@@ -54,7 +68,7 @@ export const ContinuePage = () => {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (disableContinue) {
 | 
					  if (disableContinue) {
 | 
				
			||||||
    window.location.href = redirectUri!;
 | 
					    window.location.href = redirectUri;
 | 
				
			||||||
    return (
 | 
					    return (
 | 
				
			||||||
      <ContinuePageLayout>
 | 
					      <ContinuePageLayout>
 | 
				
			||||||
        <Text size="xl" fw={700}>
 | 
					        <Text size="xl" fw={700}>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -24,9 +24,10 @@ import { TailscaleIcon } from "../icons/tailscale";
 | 
				
			|||||||
export const LoginPage = () => {
 | 
					export const LoginPage = () => {
 | 
				
			||||||
  const queryString = window.location.search;
 | 
					  const queryString = window.location.search;
 | 
				
			||||||
  const params = new URLSearchParams(queryString);
 | 
					  const params = new URLSearchParams(queryString);
 | 
				
			||||||
  const redirectUri = params.get("redirect_uri");
 | 
					  const redirectUri = params.get("redirect_uri") ?? "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const { isLoggedIn, configuredProviders } = useUserContext();
 | 
					  const { isLoggedIn, configuredProviders } = useUserContext();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const oauthProviders = configuredProviders.filter(
 | 
					  const oauthProviders = configuredProviders.filter(
 | 
				
			||||||
    (value) => value !== "username",
 | 
					    (value) => value !== "username",
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
@@ -69,7 +70,7 @@ export const LoginPage = () => {
 | 
				
			|||||||
        color: "green",
 | 
					        color: "green",
 | 
				
			||||||
      });
 | 
					      });
 | 
				
			||||||
      setTimeout(() => {
 | 
					      setTimeout(() => {
 | 
				
			||||||
        if (redirectUri === "null") {
 | 
					        if (redirectUri === "null" || redirectUri === "") {
 | 
				
			||||||
          window.location.replace("/");
 | 
					          window.location.replace("/");
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
          window.location.replace(`/continue?redirect_uri=${redirectUri}`);
 | 
					          window.location.replace(`/continue?redirect_uri=${redirectUri}`);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,10 +5,10 @@ import { Navigate } from "react-router";
 | 
				
			|||||||
export const UnauthorizedPage = () => {
 | 
					export const UnauthorizedPage = () => {
 | 
				
			||||||
  const queryString = window.location.search;
 | 
					  const queryString = window.location.search;
 | 
				
			||||||
  const params = new URLSearchParams(queryString);
 | 
					  const params = new URLSearchParams(queryString);
 | 
				
			||||||
  const username = params.get("username");
 | 
					  const username = params.get("username") ?? "";
 | 
				
			||||||
  const resource = params.get("resource");
 | 
					  const resource = params.get("resource") ?? "";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (username === "null") {
 | 
					  if (username === "null" || username === "") {
 | 
				
			||||||
    return <Navigate to="/" />;
 | 
					    return <Navigate to="/" />;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -20,7 +20,7 @@ export const UnauthorizedPage = () => {
 | 
				
			|||||||
        </Text>
 | 
					        </Text>
 | 
				
			||||||
        <Text>
 | 
					        <Text>
 | 
				
			||||||
          The user with username <Code>{username}</Code> is not authorized to{" "}
 | 
					          The user with username <Code>{username}</Code> is not authorized to{" "}
 | 
				
			||||||
          {resource !== "null" ? (
 | 
					          {resource !== "null" && resource !== "" ? (
 | 
				
			||||||
            <span>
 | 
					            <span>
 | 
				
			||||||
              access the <Code>{resource}</Code> resource.
 | 
					              access the <Code>{resource}</Code> resource.
 | 
				
			||||||
            </span>
 | 
					            </span>
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user