0.2.2 • Published 12 months ago

cowpunk-auth v0.2.2

Weekly downloads
-
License
-
Repository
-
Last release
12 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.2.1

12 months ago

0.2.2

12 months ago

0.2.0

1 year ago

0.1.1

1 year ago

0.1.0

2 years ago

0.0.2

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.1

2 years ago