mirror of
				https://github.com/steveiliop56/tinyauth.git
				synced 2025-10-31 14:15:50 +00:00 
			
		
		
		
	 318f00993e
			
		
	
	318f00993e
	
	
	
		
			
			* wip * feat: make forms functional * feat: finalize pages * chore: remove unused translations * feat: app context * feat: user context * feat: finalize username login * fix: use correct tab order in login form * feat: add oauth logic * chore: update readme and assets * chore: rename docs back to assets * feat: favicons * feat: custom background image config option * chore: add acknowledgements for background image * feat: sanitize redirect URL * feat: sanitize redirect URL on check * chore: fix dependabot config * refactor: bot suggestions * fix: correctly redirect to app and check for untrusted redirects * fix: run oauth auto redirect only when there is a redirect URI * refactor: change select color * fix: fix dockerfiles * fix: fix hook rendering * chore: remove translations cdn * chore: formatting * feat: validate api response against zod schema * fix: use axios error instead of generic error in login page
		
			
				
	
	
		
			90 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			90 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import { Button } from "@/components/ui/button";
 | |
| import {
 | |
|   Card,
 | |
|   CardDescription,
 | |
|   CardFooter,
 | |
|   CardHeader,
 | |
|   CardTitle,
 | |
| } from "@/components/ui/card";
 | |
| import { useAppContext } from "@/context/app-context";
 | |
| import { useUserContext } from "@/context/user-context";
 | |
| import { capitalize } from "@/lib/utils";
 | |
| import { useMutation } from "@tanstack/react-query";
 | |
| import axios from "axios";
 | |
| import { Trans, useTranslation } from "react-i18next";
 | |
| import { Navigate } from "react-router";
 | |
| import { toast } from "sonner";
 | |
| 
 | |
| export const LogoutPage = () => {
 | |
|   const { provider, username, isLoggedIn, email } = useUserContext();
 | |
| 
 | |
|   if (!isLoggedIn) {
 | |
|     return <Navigate to="/login" />;
 | |
|   }
 | |
| 
 | |
|   const { genericName } = useAppContext();
 | |
|   const { t } = useTranslation();
 | |
| 
 | |
|   const logoutMutation = useMutation({
 | |
|     mutationFn: () => axios.post("/api/logout"),
 | |
|     mutationKey: ["logout"],
 | |
|     onSuccess: () => {
 | |
|       toast.success(t("logoutSuccessTitle"), {
 | |
|         description: t("logoutSuccessSubtitle"),
 | |
|       });
 | |
| 
 | |
|       setTimeout(async () => {
 | |
|         window.location.replace("/login");
 | |
|       }, 500);
 | |
|     },
 | |
|     onError: () => {
 | |
|       toast.error(t("logoutFailTitle"), {
 | |
|         description: t("logoutFailSubtitle"),
 | |
|       });
 | |
|     },
 | |
|   });
 | |
| 
 | |
|   return (
 | |
|     <Card className="min-w-xs sm:min-w-sm">
 | |
|       <CardHeader>
 | |
|         <CardTitle className="text-3xl">{t("logoutTitle")}</CardTitle>
 | |
|         <CardDescription>
 | |
|           {provider !== "username" ? (
 | |
|             <Trans
 | |
|               i18nKey="logoutOauthSubtitle"
 | |
|               t={t}
 | |
|               components={{
 | |
|                 code: <code />,
 | |
|               }}
 | |
|               values={{
 | |
|                 username: email,
 | |
|                 provider:
 | |
|                   provider === "generic" ? genericName : capitalize(provider),
 | |
|               }}
 | |
|             />
 | |
|           ) : (
 | |
|             <Trans
 | |
|               i18nKey="logoutUsernameSubtitle"
 | |
|               t={t}
 | |
|               components={{
 | |
|                 code: <code />,
 | |
|               }}
 | |
|               values={{
 | |
|                 username,
 | |
|               }}
 | |
|             />
 | |
|           )}
 | |
|         </CardDescription>
 | |
|       </CardHeader>
 | |
|       <CardFooter className="flex flex-col items-stretch">
 | |
|         <Button
 | |
|           loading={logoutMutation.isPending}
 | |
|           onClick={() => logoutMutation.mutate()}
 | |
|         >
 | |
|           {t("logoutTitle")}
 | |
|         </Button>
 | |
|       </CardFooter>
 | |
|     </Card>
 | |
|   );
 | |
| };
 |