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

fix(ts): tweak Adapter related types #1914

Merged
merged 4 commits into from May 3, 2021
Merged

Conversation

balazsorban44
Copy link
Member

Reasoning 💡

  1. The first parameter of an adapter will always be something like a client that is used to communicate with a database, so we can require it. The second parameter will be reserved for any additional configuration for the adapter.

  2. some parameters in the AppOptions interface were nullable, but in reality, we set a default for almost all of them here:

    req.options = {
    debug: false,
    pages: {},
    theme: 'auto',
    // Custom options override defaults
    ...userOptions,
    // These computed settings can have values in userOptions but we override them
    // and are request-specific.
    adapter,
    baseUrl,
    basePath,
    action,
    provider,
    cookies,
    secret,
    providers,
    // Session options
    session: {
    jwt: !adapter, // If no adapter specified, force use of JSON Web Tokens (stateless)
    maxAge,
    updateAge: 24 * 60 * 60, // Sessions updated only if session is greater than this value (0 = always, 24*60*60 = every 24 hours)
    ...userOptions.session
    },
    // JWT options
    jwt: {
    secret, // Use application secret if no keys specified
    maxAge, // same as session maxAge,
    encode: jwt.encode,
    decode: jwt.decode,
    ...userOptions.jwt
    },
    // Event messages
    events: {
    ...defaultEvents,
    ...userOptions.events
    },
    // Callback functions
    callbacks: {
    ...defaultCallbacks,
    ...userOptions.callbacks
    },
    pkce: {},
    logger
    }

This means that the internal interface for AppOptions can be assumed to have much more non-nullable fields and thus playing better with the Adapter interface and when it is used to type custom adapters.

Checklist 🧢

Feel free cross items ( like this ~[] item~ ) if they're irrelevant to your changes.

To check an item, place an x in the box like so: - [x] Documentation.

  • Documentation
  • Tests
  • Ready to be merged

Affected issues 🎟

@vercel
Copy link

vercel bot commented May 3, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/nextauthjs/next-auth/94PvhQXSUsnMqGxE1R49PdDkPAQd
✅ Preview: https://next-auth-git-fix-tweak-adapter-types-nextauthjs.vercel.app

@github-actions github-actions bot added the TypeScript Issues relating to TypeScript label May 3, 2021
@vercel vercel bot temporarily deployed to Preview May 3, 2021 12:35 Inactive
@vercel vercel bot temporarily deployed to Preview May 3, 2021 12:42 Inactive
@github-actions github-actions bot added the test Related to testing label May 3, 2021
Copy link
Collaborator

@ubbe-xyz ubbe-xyz left a comment

Choose a reason for hiding this comment

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

Coolios 📐

@ubbe-xyz ubbe-xyz merged commit 6df0d04 into main May 3, 2021
@ubbe-xyz ubbe-xyz deleted the fix/tweak-adapter-types branch May 3, 2021 19:24
balazsorban44 added a commit that referenced this pull request May 6, 2021
* Constrain the adapters type generics more accurately

* Add types for the incoming messages to events callbacks

* Code review comments from @lluia

* Rebase from trunk and fix merge conflicts

* Update documentation

* Rip out generics

* fix(build): export aliases from client (#1909)

* docs(provider): update providers documentation (#1900)

* docs(providers): update providers documentation

- delineate clearly the 3 provider types (oauth, email, credentials)
- make each section structure consistent
- update the option list for every provider type
- use emojis

* docs(providers): instructions on new provider types

* docs(providers): remove emojis

To stay consistent with the rest of our documentation, for now we should not emojis on the sections of our documentation pages.

* docs(providers): reword sentence

Co-authored-by: Balázs Orbán <info@balazsorban.com>

* docs(providers): add tip on overriding options

* docs(providers): clarify `params` option usage

* docs(providers): make names list inline

Co-authored-by: Balázs Orbán <info@balazsorban.com>

* fix(ts): unset generics defaults for overriding (#1891)

Co-authored-by: Lluis Agusti <hi@llu.lu>

* fix(ts): tweak Adapter related types (#1914)

Contains the following squashed commits:

* fix(ts): make first adapter parameter non-optional
* fix(ts): make defaulted values non-optional internally
* test(ts): fix linting

* fix(page): don't pass params to custom signout page (#1912)

* For the custom signout page addressed two issues with the query params being added to the signout url. A conditional check on the error value is now made before adding it as a query param. Also added a conditional check on the callbackUrl and if present that then gets appended as a query param to the signout api call.

* Changed fix for bug #192 to have no querystring params in the custom signout page url.

Co-authored-by: anubisoft <anubisoftprez@gmail.com>
Co-authored-by: Lluis Agusti <hi@llu.lu>

* docs(www): fix typo (#1922)

* docs(provider): Update IdentityServer 4 demo configuration (#1932)

* Responding to code review comments

* Fix tests

* Fix lint error

Co-authored-by: Lluis Agusti <hi@llu.lu>
Co-authored-by: Balázs Orbán <info@balazsorban.com>
Co-authored-by: Kristóf Poduszló <kripod@protonmail.com>
Co-authored-by: Anubisoft <1471887+anubisoft@users.noreply.github.com>
Co-authored-by: anubisoft <anubisoftprez@gmail.com>
Co-authored-by: Ernie Miranda <emiranda04@users.noreply.github.com>
Co-authored-by: Mathis Møller <thisen-dk@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
test Related to testing TypeScript Issues relating to TypeScript
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants