Skip to content

Commit

Permalink
✨ feat: Update script and context for AppWriteProvider
Browse files Browse the repository at this point in the history
Adds default context values for AppWriteProvider and updates type imports.

The changes introduce default values for the AppWriteContext, ensuring that
any consumer of the context will receive a complete object with all necessary
functions and state, even if the provider is not found in the component tree.
This prevents potential runtime errors when attempting to destructure or
invoke context values that would otherwise be undefined.

Additionally, the changes clean up the import statements for types, ensuring
that type imports are consistent and follow project conventions. This helps
maintain code readability and project structure.
  • Loading branch information
Gincioks committed May 5, 2024
1 parent 900d308 commit a448955
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"scripts": {
"build": "npm run build:libs && npm run build:types",
"build:libs": "rollup -c",
"build:types": "tsc --declaration --emitDeclarationOnly --outDir types",
"build:types": "rm -r types && tsc --declaration --emitDeclarationOnly --outDir types",
"ci": "bun run lint:circular && bun run type-check",
"clean": "rm -r es lib dist coverage .eslintcache node_modules/.cache",
"lint:circular": "dpdm src/**/*.{ts,tsx} --warning false --tree false --exit-code circular:1 -T true",
Expand Down
15 changes: 14 additions & 1 deletion src/lib/AppWriteProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,20 @@ export type AppWriteContextType = {
isAuthenticationLoading: boolean;
};

const AppWriteContext = createContext<AppWriteContextType | undefined>(undefined);
const AppWriteContext = createContext<AppWriteContextType>({
signUp: async () => {
throw new Error('AppWriteProvider not found');
},
signIn: async () => {
throw new Error('AppWriteProvider not found');
},
signOut: async () => {
throw new Error('AppWriteProvider not found');
},
isAuthenticated: false,
user: undefined,
isAuthenticationLoading: true,
});

export const useAppWrite = () => useContext(AppWriteContext);

Expand Down
2 changes: 1 addition & 1 deletion types/lib/AppWriteProvider.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ export declare type AppWriteContextType = {
user: Models.Document | undefined;
isAuthenticationLoading: boolean;
};
export declare const useAppWrite: () => AppWriteContextType | undefined;
export declare const useAppWrite: () => AppWriteContextType;
export declare const AppWriteProvider: FC<AppWriteProviderProps>;
8 changes: 4 additions & 4 deletions types/lib/app-write-auth.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { type AppwriteConfigType } from './AppWriteProvider';
export declare const appWriteAuth: (config: AppwriteConfigType) => {
signUp: (email: string, password: string, username: string) => Promise<import("../models").Models.Document>;
signIn: (email: string, password: string) => Promise<import("../models").Models.Session>;
getAccount: () => Promise<import("../models").Models.User<import("../models").Models.Preferences>>;
getCurrentUser: () => Promise<import("../models").Models.Document | null>;
signUp: (email: string, password: string, username: string) => Promise<import("client").Models.Document>;
signIn: (email: string, password: string) => Promise<import("client").Models.Session>;
getAccount: () => Promise<import("client").Models.User<import("client").Models.Preferences>>;
getCurrentUser: () => Promise<import("client").Models.Document | null>;
signOut: () => Promise<{}>;
};

0 comments on commit a448955

Please sign in to comment.