mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
🤖 Merge PR #48140 [next-auth] Allow session to be null or undefined by @bjohn465
While the session data is being fetched, `useSession` will return `undefined`. If a session doesn't exist, `useSession` will return `null`. The result of `useSession` is commonly passed to the `Provider` component (e.g. see the examples at https://next-auth.js.org/getting-started/client#provider), and it seems to allow the `undefined` and `null` values for the `session` prop, so allow them in the type information, too.
This commit is contained in:
parent
71e26e0445
commit
f7d569cf92
4
types/next-auth/client.d.ts
vendored
4
types/next-auth/client.d.ts
vendored
@ -25,7 +25,7 @@ interface SessionProvider extends GenericObject {
|
||||
}
|
||||
|
||||
interface ContextProviderProps {
|
||||
session: Session;
|
||||
session: Session | null | undefined;
|
||||
options?: SetOptionsParams;
|
||||
}
|
||||
|
||||
@ -43,7 +43,7 @@ interface NextContext {
|
||||
ctx?: { req: IncomingMessage };
|
||||
}
|
||||
|
||||
declare function useSession(): [Session, boolean];
|
||||
declare function useSession(): [Session | null | undefined, boolean];
|
||||
declare function providers(): Promise<GetProvidersResponse | null>;
|
||||
declare const getProviders: typeof providers;
|
||||
declare function session(
|
||||
|
||||
@ -190,7 +190,7 @@ const session = {
|
||||
expires: '1234',
|
||||
};
|
||||
|
||||
// $ExpectType [Session, boolean]
|
||||
// $ExpectType [Session | null | undefined, boolean]
|
||||
client.useSession();
|
||||
|
||||
// $ExpectType Promise<Session | null>
|
||||
@ -230,6 +230,28 @@ client.Provider({
|
||||
},
|
||||
});
|
||||
|
||||
// $ExpectType ReactElement<any, any> | null
|
||||
client.Provider({
|
||||
session,
|
||||
});
|
||||
|
||||
// $ExpectType ReactElement<any, any> | null
|
||||
client.Provider({
|
||||
session: undefined,
|
||||
options: {},
|
||||
});
|
||||
|
||||
// $ExpectType ReactElement<any, any> | null
|
||||
client.Provider({
|
||||
session: null,
|
||||
options: {
|
||||
baseUrl: 'https://foo.com',
|
||||
basePath: '/',
|
||||
clientMaxAge: 1234,
|
||||
keepAlive: 4321,
|
||||
},
|
||||
});
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// Providers
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
Loading…
Reference in New Issue
Block a user