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

docs: Fix safeGetSession Type Definition and Missing Import in SvelteKit Guide (#26280) #27192

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Surjeet9700
Copy link
Contributor

The type definition for the safeGetSession function in app.d.ts has been updated to include an optional user property in the returned Promise. This change ensures compatibility with the latest version of @supabase/supabase-js.

I have read the CONTRIBUTING.md file.

YES

What kind of change does this PR introduce?

docs update

What is the current behavior?

The provided type definition for safeGetSession in app.d.ts causes a TypeScript error in files like +layout.ts because it expects a user property that doesn't always exist in the return value.
The app.d.ts file is missing an import for the User type, causing another TypeScript error.

What is the new behavior?

The user property in the safeGetSession return type is marked as optional (user?: User | null) to accommodate cases where it might not be present.
The missing User type import is added to app.d.ts.
This resolves the TypeScript errors and ensures the code compiles correctly without unexpected type mismatches.

Feel free to include screenshots if it includes visual changes.

Additional context

This PR addresses issue #26280 The changes are minimal but important for ensuring the accuracy and usability of the documentation and type definitions.

Add any other context or screenshots.

`// src/app.d.ts
import type { SupabaseClient, Session, User } from '@supabase/supabase-js'; // Added User import

declare global {
namespace App {
interface Locals {
supabase: SupabaseClient;
safeGetSession(): Promise<{ session: Session | null; user?: User | null }>; // user is now optional
}
interface PageData {
session: Session | null;
user?: User | null; // user is now optional
}
// interface Error {}
// interface Platform {}
}
}
`

The type definition for the `safeGetSession` function in `app.d.ts` has been updated to include an optional `user` property in the returned Promise. This change ensures compatibility with the latest version of `@supabase/supabase-js`.
Copy link

vercel bot commented Jun 11, 2024

@Surjeet9700 is attempting to deploy a commit to the Supabase Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

@charislam charislam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Surjeet9700!

Definitely the type needs to be added, but the return type for safeGetSession I'm a bit confused by. I'm looking at the function definition and not seeing a case where user would be missing, mind pointing me to the location?

@Surjeet9700
Copy link
Contributor Author

You're absolutely right, I apologize for the confusion. I was working under the assumption that the safeGetSession function might not always return a user object.

However, after re-examining the implementation within the context of this project, I can confirm that the function indeed consistently returns a user object along with the session. Therefore, the optional user property might not be necessary.

I'll update the pull request to remove the optional nature of the user property in the safeGetSession return type. Thank you for bringing this to my attention!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants