🤖 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:
Brandon Johnson 2020-09-24 14:54:24 -06:00 committed by GitHub
parent 71e26e0445
commit f7d569cf92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 3 deletions

View File

@ -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(

View File

@ -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
// --------------------------------------------------------------------------