🤖 Merge PR #47130 [next-auth] Fixed signIn, set optional conext, and set optional ID in credentials by @JuanM04

* Fixed signIn / signOut

* Optional NextPageContext

* Optional ID on ProvideCredentials

* Updated tests

* Added callbackUrl and fixed signout

* Providers order
This commit is contained in:
JuanM04 2020-09-01 16:34:06 -03:00 committed by GitHub
parent 893c701b3d
commit 193b41d31c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 48 deletions

View File

@ -47,15 +47,20 @@ interface SetOptionsParams {
type ContextProvider = FC<ContextProviderProps>;
declare function useSession(): [Session, boolean];
declare function providers(context: NextPageContext): Promise<GetProvidersResponse | null>;
declare function providers(context?: NextPageContext): Promise<GetProvidersResponse | null>;
declare const getProviders: typeof providers;
declare function session(context: NextPageContext): Promise<Session | null>;
declare function session(context?: NextPageContext): Promise<Session | null>;
declare const getSession: typeof session;
declare function csrfToken(context: NextPageContext): Promise<string | null>;
declare function csrfToken(context?: NextPageContext): Promise<string | null>;
declare const getCsrfToken: typeof csrfToken;
declare function signin(provider: SessionProvider, data: GenericObject): Promise<void>;
declare function signin(
provider?: string,
data?: GenericObject & {
callbackUrl?: string;
},
): Promise<void>;
declare const signIn: typeof signin;
declare function signout(context: NextPageContext): Promise<void>;
declare function signout(data?: { callbackUrl?: string }): Promise<void>;
declare const signOut: typeof signout;
declare function options(options: SetOptionsParams): void;
declare const setOptions: typeof options;

View File

@ -221,10 +221,13 @@ client.getCsrfToken(pageContext);
client.csrfToken(pageContext);
// $ExpectType Promise<void>
client.signin(githubProvider, { data: 'foo' });
client.signin('github', { data: 'foo' });
// $ExpectType Promise<void>
client.signout(pageContext);
client.signout();
// $ExpectType Promise<void>
client.signout({ callbackUrl: 'https://foo.com/callback' });
// $ExpectType ReactElement<any, any> | null
client.Provider({

View File

@ -1,53 +1,30 @@
export interface Providers {
Email: Email;
Credentials: Credentials;
Apple: Apple;
Twitter: Twitter;
Facebook: Facebook;
GitHub: GitHub;
GitLab: GitLab;
Slack: Slack;
Google: Google;
Auth0: Auth0;
IdentityServer4: IdentityServer4;
Discord: Discord;
Twitch: Twitch;
Mixer: Mixer;
Okta: Okta;
Basecamp: Basecamp;
BattleNet: BattleNet;
Box: Box;
Cognito: Cognito;
Yandex: Yandex;
Credentials: Credentials;
Discord: Discord;
Email: Email;
Facebook: Facebook;
GitHub: GitHub;
GitLab: GitLab;
Google: Google;
IdentityServer4: IdentityServer4;
LinkedIn: LinkedIn;
Spotify: Spotify;
Basecamp: Basecamp;
Mixer: Mixer;
Okta: Okta;
Reddit: Reddit;
Slack: Slack;
Spotify: Spotify;
Twitch: Twitch;
Twitter: Twitter;
Yandex: Yandex;
}
type PossibleProviders =
| Email
| Credentials
| Apple
| Twitter
| Facebook
| GitHub
| GitLab
| Slack
| Google
| Auth0
| IdentityServer4
| Discord
| Twitch
| Mixer
| Okta
| BattleNet
| Box
| Cognito
| Yandex
| LinkedIn
| Spotify
| Basecamp
| Reddit;
type PossibleProviders = Providers[keyof Providers];
// TODO: type return objects from providers properly
interface GenericReturnConfig {
@ -94,7 +71,7 @@ interface ProviderEmailAuth {
type Credentials = (options: ProviderCredentialsOptions) => GenericReturnConfig;
interface ProviderCredentialsOptions {
id: string;
id?: string;
name: string;
credentials: unknown;
authorize(credentails: unknown): Promise<unknown | null>;