1
0
mirror of synced 2025-12-25 20:00:13 -05:00
Files
blitz/packages/blitz-auth
René Vlugt 030c8135b9 Upgrade cookie-session dependency to v2.1.1 (#4442)
* Upgrade cookie-session dependency to v2.1.1

* Add changeset

* update workflow dependencies

---------

Co-authored-by: Siddharth Suresh <siddh.suresh@gmail.com>
# Conflicts:
#	pnpm-lock.yaml
2025-09-11 18:15:48 +05:30
..
2025-03-03 14:22:57 +05:30
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}