# @ibercore/next-auth

> Next Auth Library multiple providers

Latest version **1.5.15** (published 2023-07-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install @ibercore/next-auth
pnpm add @ibercore/next-auth
yarn add @ibercore/next-auth
bun add @ibercore/next-auth
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.5.15 |
| Published | 2023-07-14 |
| First published | 2023-01-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 8 |
| Unpacked size | 94.2 KB |
| Known vulnerabilities | 0 (+23 in 2 direct dependencies) |
| Install scripts | no |
| Author | IBERCORE LLC |
| Maintainers | alfredo.ochoa |

## Links

- npm: https://www.npmjs.com/package/@ibercore/next-auth
- Repository: https://github.com/ibercore/next-auth
- Homepage: https://github.com/ibercore/next-auth#readme
- Issues: https://github.com/ibercore/next-auth/issues
- npm.io page: https://npm.io/package/@ibercore/next-auth

## Dependencies (8)

- [jose](https://npm.io/package/jose.md) ^4.11.2
- [uuid](https://npm.io/package/uuid.md) ^9.0.0
- [axios](https://npm.io/package/axios.md) ^1.2.4
- [chalk](https://npm.io/package/chalk.md) ^4.1.2
- [lodash](https://npm.io/package/lodash.md) ^4.17.21
- [nodemailer](https://npm.io/package/nodemailer.md) ^6.9.1
- [@panva/hkdf](https://npm.io/package/@panva/hkdf.md) ^1.0.2
- [cookies-next](https://npm.io/package/cookies-next.md) ^2.1.1

## Recent versions

- 1.5.15 (latest) — 2023-07-14
- 1.5.14 — 2023-05-09
- 1.5.13 — 2023-05-09
- 1.5.12 — 2023-05-09
- 1.5.11 — 2023-05-09
- 1.5.10 — 2023-05-07
- 1.5.7 — 2023-03-23
- 1.5.6 — 2023-03-23
- 1.5.5 — 2023-03-23
- 1.5.4 — 2023-03-23
- 1.5.3 — 2023-03-22
- 1.5.2 — 2023-03-20
- 1.5.1 — 2023-03-18
- 1.4.9 — 2023-03-03
- 1.4.8 — 2023-03-03
- … 44 more at https://npm.io/package/@ibercore/next-auth/versions

## README

# @ibercore/next-auth

> Next Auth Library multiple providers

[![NPM](https://img.shields.io/npm/v/@ibercore/next-auth.svg)](https://www.npmjs.com/package/@ibercore/next-auth) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

## Install

```bash
npm install --save @ibercore/next-auth
```

## Client Side
```tsx
// pages/_app.tsx
import type { AppProps } from 'next/app'
import React, { Component } from 'react'
import { SessionProvider, useSession } from '@ibercore/next-auth'

export default function App({ Component, pageProps }: AppProps) {
  return <SessionProvider>
    <Auth>
      <Component {...pageProps} />
    </Auth>
  </SessionProvider>
}

const Auth = ({ children }: { children: any }): any => {
  const { status } = useSession()
  if (status === 'loading') return <p>Loading...</p>
  if (status === 'unauthenticated') return <SignIn />
  return children
}
```

```tsx
// pages/signin.tsx
import { useSession } from "@ibercore/next-auth"

const SignIn = () => {
    const { signIn } = useSession()
    return <div>
        {/* Create form with two inputs username & password and call on submit */}
        <button onClick={() => signIn('credentials', { username: 'test', password: 'test' })} >CREDENTIALS</button>
        <button onClick={() => signIn('facebook')}> FACEBOOK</button>
        <button onClick={() => signIn('google')}> GOOGLE</button>
    </div>
}

export default SignIn;
```

## Configure API
```ts
// pages/auth/api/[...nextauth].ts
import { NextAuth, NextAuthOptions } from "@ibercore/next-auth";
import CredentialProvider from "@ibercore/next-auth/providers/credentials";
import GoogleProvider from "@ibercore/next-auth/providers/google";
import FacebookProvider from "@ibercore/next-auth/providers/facebook";
import EmailProvider from "@ibercore/next-auth/providers/email"


export default function handler(res, req) {
    const nextAuthOptions: NextAuthOptions = {
        secret: process.env.NEXTAUTH_SECRET,
        callbacks: {
            async signIn({ session, provider }) {
                console.log("callbacks signIn", { session, provider })
            },
            async signOut({ session, provider }) {
                console.log("callbacks signOut", { session, provider })
            }
        },
        pages: {
            signIn: '/'
        },
        providers: [
            EmailProvider({
                from: process.env.EMAIL_FROM,
                server: {
                    host: process.env.EMAIL_HOST,
                    user: process.env.EMAIL_USER,
                    pass: process.env.EMAIL_PASS
                }
            }),
            CredentialProvider({
                async authorize(credentials) {
                    const user = {
                        id: '222',
                        role: 'role',
                        name: 'User',
                        lastName: 'Name',
                    }
                    if (!user) return null
                    const validate = true
                    if (!validate) return null
                    return user
                },
            }),
            GoogleProvider({
                clientId: process.env.GOOGLE_CLIENT_ID!,
                clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
            }),
            FacebookProvider({
                clientId: process.env.FACEBOOK_CLIENT_ID!,
                clientSecret: process.env.FACEBOOK_CLIENT_SECRET!,
            }),

        ]
    }

    return NextAuth(res, req, nextAuthOptions)
}

```

## Options

``` text
NextAuthOptions



```

## Notes 
If you are using EmailProvider add this on you package.json
```json
"browser": {
    "fs": false,
    "os": false,
    "path": false,
    "net": false,
    "dns": false,
    "child_process": false,
    "tls": false
}
```
## License

MIT © [](https://github.com/)

---
_Source: https://npm.io/package/@ibercore/next-auth · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
