Use kv datastore for auth (#272)
This commit is contained in:
parent
d741351e26
commit
b6cab643ef
10 changed files with 143 additions and 173 deletions
19
auth.ts
19
auth.ts
|
|
@ -2,25 +2,8 @@ import NextAuth from 'next-auth'
|
|||
import Credentials from 'next-auth/providers/credentials'
|
||||
import { authConfig } from './auth.config'
|
||||
import { z } from 'zod'
|
||||
import { sql } from '@vercel/postgres'
|
||||
import { getStringFromBuffer } from './lib/utils'
|
||||
|
||||
interface User {
|
||||
id: string
|
||||
name: string
|
||||
email: string
|
||||
password: string
|
||||
salt: string
|
||||
}
|
||||
|
||||
async function getUser(email: string): Promise<User | undefined> {
|
||||
try {
|
||||
const user = await sql<User>`SELECT * FROM users WHERE email=${email}`
|
||||
return user.rows[0]
|
||||
} catch (error) {
|
||||
throw new Error('Failed to fetch user.')
|
||||
}
|
||||
}
|
||||
import { getUser } from './app/login/actions'
|
||||
|
||||
export const { auth, signIn, signOut } = NextAuth({
|
||||
...authConfig,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue