1
0
mirror of synced 2025-12-25 11:00:31 -05:00
Files
blitz/packages/blitz-auth
github-actions[bot] ae04524b4c Version Packages (#4397)
* Version Packages

* pnpm lock update

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Siddharth Suresh <siddh.suresh@gmail.com>
2024-12-23 12:03:32 +00:00
..
2024-12-23 12:03:32 +00:00
2024-12-23 12:03:32 +00:00
2023-07-12 13:13:51 +00:00

Blitz.js


Blitz Auth - Framework Agnostic Authentication


Documentation Link

GitHub Link

Quick Start

Install Blitz Auth

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

You can alternatively use 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:

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:

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}