Skip to content

Commit

Permalink
Merge pull request #63 from marmelab/compile-with-strict-null-checks
Browse files Browse the repository at this point in the history
Enable strictNullChecks
  • Loading branch information
adguernier authored Jul 3, 2024
2 parents 38f298b + ef4871e commit 33107c4
Show file tree
Hide file tree
Showing 14 changed files with 197 additions and 37 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"lerna": "^6.6.2",
"prettier": "~2.8.8",
"raf": "^3.4.1",
"supabase": "^1.131.2",
"supabase": "^1.178.2",
"typescript": "^4.9.5",
"ts-jest": "^29.1.0",
"whatwg-fetch": "^3.0.0"
Expand Down
19 changes: 10 additions & 9 deletions packages/ra-supabase-core/src/authProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export const supabaseAuthProvider = (
client: SupabaseClient,
{ getIdentity, getPermissions, redirectTo }: SupabaseAuthProviderOptions
): SupabaseAuthProvider => {
return {
const authProvider: SupabaseAuthProvider = {
async login(params) {
const emailPasswordParams = params as LoginWithEmailPasswordParams;
if (emailPasswordParams.email && emailPasswordParams.password) {
Expand Down Expand Up @@ -153,21 +153,22 @@ export const supabaseAuthProvider = (
}
return undefined;
},
async getIdentity() {
};

if (typeof getIdentity === 'function') {
authProvider.getIdentity = async () => {
const { data } = await client.auth.getUser();

if (data.user == null) {
throw new Error();
}

if (typeof getIdentity === 'function') {
const identity = await getIdentity(data.user);
return identity;
}
const identity = await getIdentity(data.user);
return identity;
};
}

return undefined;
},
};
return authProvider;
};

export type GetIdentity = (user: User) => Promise<UserIdentity>;
Expand Down
12 changes: 12 additions & 0 deletions packages/ra-supabase-core/src/useResetPassword.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ export const useResetPassword = (
const notify = useNotify();
const authProvider = useAuthProvider<SupabaseAuthProvider>();

if (authProvider == null) {
throw new Error(
'No authProvider found. Did you forget to set up an AuthProvider on the <Admin> component?'
);
}

if (authProvider.resetPassword == null) {
throw new Error(
'The setPassword() method is missing from the AuthProvider although it is required. You may consider adding it'
);
}

const {
onSuccess = () => {
notify('ra-supabase.auth.password_reset', { type: 'info' });
Expand Down
12 changes: 12 additions & 0 deletions packages/ra-supabase-core/src/useSetPassword.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ export const useSetPassword = (
const redirect = useRedirect();
const authProvider = useAuthProvider<SupabaseAuthProvider>();

if (authProvider == null) {
throw new Error(
'No authProvider found. Did you forget to set up an AuthProvider on the <Admin> component?'
);
}

if (authProvider.setPassword == null) {
throw new Error(
'The setPassword() method is missing from the AuthProvider although it is required. You may consider adding it'
);
}

const {
onSuccess = () => redirect('/'),
onError = error => notify(error.message, { type: 'error' }),
Expand Down
3 changes: 2 additions & 1 deletion packages/ra-supabase-core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"rootDir": "src",
"declaration": true,
"declarationMap": true,
"allowJs": false
"allowJs": false,
"strictNullChecks": true
},
"exclude": ["**/*.spec.ts", "**/*.spec.tsx", "**/*.spec.js"],
"include": ["src"],
Expand Down
1 change: 1 addition & 0 deletions packages/ra-supabase-language-english/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const raSupabaseEnglishMessages = {
reset_password: 'Reset password',
password_reset:
'Your password has been reset. You will receive an email containing a link to log in.',
missing_tokens: 'Access and refresh tokens are missing',
},
validation: {
password_mismatch: 'Passwords do not match',
Expand Down
3 changes: 2 additions & 1 deletion packages/ra-supabase-language-english/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"rootDir": "src",
"declaration": true,
"declarationMap": true,
"allowJs": false
"allowJs": false,
"strictNullChecks": true
},
"exclude": ["**/*.spec.ts", "**/*.spec.tsx", "**/*.spec.js"],
"include": ["src"]
Expand Down
2 changes: 2 additions & 0 deletions packages/ra-supabase-language-french/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export const raSupabaseFrenchMessages = {
reset_password: 'Réinitialiser le mot de passe',
password_reset:
'Votre mot de passe a été réinitialisé. Vous recevrez un email contenant un lien pour vous connecter.',
missing_tokens:
"Les jetons d'accès et de rafraîchissement sont manquants",
},
validation: {
password_mismatch: 'Les mots de passe ne correspondent pas',
Expand Down
3 changes: 2 additions & 1 deletion packages/ra-supabase-language-french/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"rootDir": "src",
"declaration": true,
"declarationMap": true,
"allowJs": false
"allowJs": false,
"strictNullChecks": true
},
"exclude": ["**/*.spec.ts", "**/*.spec.tsx", "**/*.spec.js"],
"include": ["src"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const ForgotPasswordForm = () => {
};

interface FormData {
email?: string;
email: string;
}

const PREFIX = 'RaSupabaseForgotPasswordForm';
Expand Down
20 changes: 17 additions & 3 deletions packages/ra-supabase-ui-materialui/src/SetPasswordForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const SetPasswordForm = () => {
const refresh_token = useSupabaseAccessToken({
parameterName: 'refresh_token',
});

const notify = useNotify();
const translate = useTranslate();
const [setPassword] = useSetPassword({
Expand Down Expand Up @@ -45,9 +46,22 @@ export const SetPasswordForm = () => {
confirmPassword: 'ra-supabase.validation.password_mismatch',
};
}
return undefined;
return {};
};

if (!access_token || !refresh_token) {
if (process.env.NODE_ENV === 'development') {
console.error(
'Missing access_token or refresh_token for set password'
);
}
return (
<div className={SupabaseLoginFormClasses.container}>
<div>{translate('ra-supabase.auth.missing_tokens')}</div>
</div>
);
}

const submit = (values: FormData) => {
return setPassword({
access_token,
Expand Down Expand Up @@ -94,8 +108,8 @@ export const SetPasswordForm = () => {
};

interface FormData {
password?: string;
confirmPassword?: string;
password: string;
confirmPassword: string;
}

const PREFIX = 'RaSupabaseSetPasswordForm';
Expand Down
3 changes: 2 additions & 1 deletion packages/ra-supabase-ui-materialui/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"rootDir": "src",
"declaration": true,
"declarationMap": true,
"allowJs": false
"allowJs": false,
"strictNullChecks": true
},
"exclude": ["**/*.spec.ts", "**/*.spec.tsx", "**/*.spec.js"],
"include": ["src"]
Expand Down
3 changes: 2 additions & 1 deletion packages/ra-supabase/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"rootDir": "src",
"declaration": true,
"declarationMap": true,
"allowJs": false
"allowJs": false,
"strictNullChecks": true
},
"exclude": ["**/*.spec.ts", "**/*.spec.tsx", "**/*.spec.js"],
"include": ["src"]
Expand Down
Loading

0 comments on commit 33107c4

Please sign in to comment.