[![Blitz.js](https://raw.githubusercontent.com/blitz-js/art/master/github-cover-photo.png)](https://blitzjs.com)

<!-- prettier-ignore-start -->
<p align="center">
  <a aria-label="Join our Discord Community" href="https://discord.blitzjs.com">
    <img alt="" src="https://img.shields.io/badge/Join%20our%20community-6700EB.svg?style=for-the-badge&labelColor=000000&logoWidth=20&logo=data:image/png;base64, ">
  </a>
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
<a aria-label="All Contributors" href="#contributors-"><img alt="" src="https://img.shields.io/badge/all_contributors-403-17BB8A.svg?style=for-the-badge&labelColor=000000"></a>
<!-- ALL-CONTRIBUTORS-BADGE:END -->
  <a aria-label="License" href="https://github.com/blitz-js/blitz/blob/main/LICENSE">
    <img alt="" src="https://img.shields.io/npm/l/blitz.svg?style=for-the-badge&labelColor=000000&color=blue">
  </a>
  <a aria-label="NPM version" href="https://www.npmjs.com/package/@blitzjs/auth">
    <img alt="" src="https://img.shields.io/npm/v/blitz.svg?style=for-the-badge&labelColor=000000&color=E65528">
  </a>
</p>
<!-- prettier-ignore-end -->

<br>

<h1 align="center">
Blitz Auth - Framework Agnostic Authentication
</h1>

<br>

### [Documentation Link](https://blitzjs.com/docs/auth)

### [GitHub Link](https://github.com/blitz-js/blitz/tree/main/packages/blitz-auth)

### Quick Start

#### Install Blitz Auth

```bash
`npm i @blitzjs/auth`
# yarn add @blitzjs/auth
# pnpm add @blitzjs/auth
```

_You can alternatively use [`npx`](https://www.npmjs.com/package/npx)_

### Framework Support

Currently Blitz Auth usage is only documented with Next.js. We are working on adding additional support for other frameworks.

#### Setup Blitz Auth in Next.js

##### Client setup

Add the following to your blitz-client.ts file:

```ts
import {AuthClientPlugin} from "@blitzjs/auth"
import {setupBlitzClient} from "@blitzjs/next"

export const authConfig = {
  cookiePrefix: "testapp",
}

const {withBlitz} = setupBlitzClient({
  plugins: [AuthClientPlugin(authConfig)],
})

export {withBlitz}
```

##### Server setup

Then, add the following to the blitz-server.ts file:

```ts
import {setupBlitzServer} from "@blitzjs/next"
import {AuthServerPlugin, PrismaStorage, simpleRolesIsAuthorized} from "@blitzjs/auth"
import {db} from "db"
import {authConfig} from "./blitz-client"

const {gSSP, gSP, api} = setupBlitzServer({
  plugins: [
    AuthServerPlugin({
      ...authConfig,
      storage: PrismaStorage(db),
      isAuthorized: simpleRolesIsAuthorized,
    }),
  ],
})

export {gSSP, gSP, api}
```
