Can we handle signing in with arbitrary credentials?

Like Next-Auth with credentials provider feature, my use case has to handle with sign in with specific auth flow that uses an authorization code (isn´t magic link).
Basically the user sign flow is to be redirected to third-party system and came back with an authorization code that I verify if its valid.

providers: [
  CredentialsProvider({
    // The name to display on the sign in form (e.g. "Sign in with...")
    name: "Credentials",
    // `credentials` is used to generate a form on the sign in page.
    // You can specify which fields should be submitted, by adding keys to the `credentials` object.
    // e.g. domain, username, password, 2FA token, etc.
    credentials: {
      code: { label: "code", type: "text" },
    },
    async authorize(credentials, req) {
      // Add logic here to look up the user from the credentials supplied
      const code = { code: "123" }

      const user = fetch user based on code

      if (user) {
        // Any object returned will be saved in `user` property of the JWT
        return user
      } else {
        // If you return null then an error will be displayed advising the user to check their details.
        return null

        // You can also Reject this callback with an Error thus the user will be sent to the error page with the error message as a query parameter
      }
    }
  })
]


Can we have something like that with Better Auth?
Was this page helpful?