Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable strictNullChecks #63

Merged
merged 2 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 authProvider does not support the resetPassword() method'
djhi marked this conversation as resolved.
Show resolved Hide resolved
);
}

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 authProvider does not support the setPassword() method'
djhi marked this conversation as resolved.
Show resolved Hide resolved
);
}

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
Loading