FullAuth

ExamplesTypescriptChangelog

Credentials Provider

In this section, you will find detailed instructions on how to use Credentials Provider with FullAuth.

Route Handler:

app/api/auth/[...fullauth]/route.ts

import { AuthOptions } from '@fullauth/core';
import { NextHandler } from '@fullauth/next';
import { CredentialsProvider } from '@fullauth/core/providers';

export const authOptions: AuthOptions = {
    providers: [
        CredentialsProvider({
            name: 'credentials',
            credentials: {
            email: { type: 'text', placeholder: 'Email' },
            password: {
                type: 'password',
                placeholder: 'Password',
            },
            },
            async signIn(credentials) {
            try {
                // you verification logic here

                // throw errors and catch them on the client side
                //     throw new Error('No User');

                return {
                email: credentials.email,
                id: 'test1',
                name: 'test',
                };
            } catch (error: any) {
                console.log(error);
                throw error;
            }
            },
        }),
    ],
    
    // Rest of code
};

const handler = NextHandler(authOptions);
export { handler as GET, handler as POST };

Multiple Providers:

app/api/auth/[...fullauth]/route.ts

import { AuthOptions } from '@fullauth/core';
import { NextHandler } from '@fullauth/next';
import { CredentialsProvider } from '@fullauth/core/providers';

export const authOptions: AuthOptions = {
    providers: [
        CredentialsProvider({
            id: 'credentials-user',
            name: 'credentials',
            credentials: {
              email: { type: 'text', placeholder: 'Email' },
              password: {
                type: 'password',
                placeholder: 'Password',
              },
            },
            async signIn(credentials) {
              try {
                // you verification logic here
      
                // throw errors and catch them on the client side
                //     throw new Error('No User');
      
                return {
                  email: credentials.email,
                  id: 'test1',
                  name: 'test',
                };
              } catch (error: any) {
                console.log(error);
                throw error;
              }
            },
          }),
          CredentialsProvider({
            id: 'credentials-admin',
            name: 'credentials',
            credentials: {
              email: { type: 'text', placeholder: 'Email' },
              password: {
                type: 'password',
                placeholder: 'Password',
              },
            },
            async signIn(credentials) {
              try {
                // you verification logic here
      
                // throw errors and catch them on the client side
                //     throw new Error('No User');
      
                return {
                  email: credentials.email,
                  id: 'test1',
                  name: 'test',
                };
              } catch (error: any) {
                console.log(error);
                throw error;
              }
            },
          }),
    ],
    
    // Rest of code
};

const handler = NextHandler(authOptions);
export { handler as GET, handler as POST };