0.1.1 • Published 3 months ago

cowpunk-auth v0.1.1

Weekly downloads
-
License
-
Repository
-
Last release
3 months ago

To install, add a file called app/config.server.ts with something like this:

import { PrismaClient } from '@prisma/client'
import { cowpunkify } from 'cowpunk-auth'

export const db = new PrismaClient()

export const auth = cowpunkify({
  site: 'Your Fabulous Site',
  loginFrom: 'Login Codez <info@yoursite.com>',
  users: db.user,
  emailCodes: db.emailCodes,
})

Copy over the routes in example-routes, and put something like this in app/routes/root.tsx so you can get the current user in your routes:

export async function loader({ request }: LoaderArgs) {
  return json({ user: await auth.getCurrentUser(request) })
}

export function useCurrentUser() {
  const { user } = useRouteLoaderData("root") as SerializeFrom<typeof loader>
  return user
}

Finally, if you have a navbar, put something like this:

  const user = useCurrentUser()
  const loginButton = user ? user.name : <Link to="/auth/login">Login</Link>
0.1.1

3 months ago

0.1.0

4 months ago

0.0.2

10 months ago

0.0.5

10 months ago

0.0.4

10 months ago

0.0.7

8 months ago

0.0.6

8 months ago

0.0.1

10 months ago