docs: Fix safeGetSession Type Definition and Missing Import in SvelteKit Guide (#26280) #27192
+2
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The type definition for the
safeGetSession
function inapp.d.ts
has been updated to include an optionaluser
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 {}
}
}
`