mirror of
				https://github.com/steveiliop56/tinyauth.git
				synced 2025-11-04 08:05:42 +00:00 
			
		
		
		
	feat: validate api response against zod schema
This commit is contained in:
		@@ -1,4 +1,7 @@
 | 
				
			|||||||
import { AppContextSchema } from "@/schemas/app-context-schema";
 | 
					import {
 | 
				
			||||||
 | 
					  appContextSchema,
 | 
				
			||||||
 | 
					  AppContextSchema,
 | 
				
			||||||
 | 
					} from "@/schemas/app-context-schema";
 | 
				
			||||||
import { createContext, useContext } from "react";
 | 
					import { createContext, useContext } from "react";
 | 
				
			||||||
import { useSuspenseQuery } from "@tanstack/react-query";
 | 
					import { useSuspenseQuery } from "@tanstack/react-query";
 | 
				
			||||||
import axios from "axios";
 | 
					import axios from "axios";
 | 
				
			||||||
@@ -19,7 +22,15 @@ export const AppContextProvider = ({
 | 
				
			|||||||
    throw error;
 | 
					    throw error;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return <AppContext.Provider value={data}>{children}</AppContext.Provider>;
 | 
					  const validated = appContextSchema.safeParse(data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (validated.success === false) {
 | 
				
			||||||
 | 
					    throw validated.error;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return (
 | 
				
			||||||
 | 
					    <AppContext.Provider value={validated.data}>{children}</AppContext.Provider>
 | 
				
			||||||
 | 
					  );
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const useAppContext = () => {
 | 
					export const useAppContext = () => {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,7 @@
 | 
				
			|||||||
import { UserContextSchema } from "@/schemas/user-context-schema";
 | 
					import {
 | 
				
			||||||
 | 
					  userContextSchema,
 | 
				
			||||||
 | 
					  UserContextSchema,
 | 
				
			||||||
 | 
					} from "@/schemas/user-context-schema";
 | 
				
			||||||
import { createContext, useContext } from "react";
 | 
					import { createContext, useContext } from "react";
 | 
				
			||||||
import { useSuspenseQuery } from "@tanstack/react-query";
 | 
					import { useSuspenseQuery } from "@tanstack/react-query";
 | 
				
			||||||
import axios from "axios";
 | 
					import axios from "axios";
 | 
				
			||||||
@@ -19,7 +22,17 @@ export const UserContextProvider = ({
 | 
				
			|||||||
    throw error;
 | 
					    throw error;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return <UserContext.Provider value={data}>{children}</UserContext.Provider>;
 | 
					  const validated = userContextSchema.safeParse(data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (validated.success === false) {
 | 
				
			||||||
 | 
					    throw validated.error;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return (
 | 
				
			||||||
 | 
					    <UserContext.Provider value={validated.data}>
 | 
				
			||||||
 | 
					      {children}
 | 
				
			||||||
 | 
					    </UserContext.Provider>
 | 
				
			||||||
 | 
					  );
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const useUserContext = () => {
 | 
					export const useUserContext = () => {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -34,7 +34,7 @@ type Config struct {
 | 
				
			|||||||
	LoginTimeout            int    `mapstructure:"login-timeout"`
 | 
						LoginTimeout            int    `mapstructure:"login-timeout"`
 | 
				
			||||||
	LoginMaxRetries         int    `mapstructure:"login-max-retries"`
 | 
						LoginMaxRetries         int    `mapstructure:"login-max-retries"`
 | 
				
			||||||
	FogotPasswordMessage    string `mapstructure:"forgot-password-message" validate:"required"`
 | 
						FogotPasswordMessage    string `mapstructure:"forgot-password-message" validate:"required"`
 | 
				
			||||||
	BackgroundImage         string `mapstructure:"background-image" validate:"required"`
 | 
						BackgroundImage         string `mapstructure:"background-image" validate:"required,url"`
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Server configuration
 | 
					// Server configuration
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user