mirror of
https://github.com/vercel/next-learn.git
synced 2026-07-09 06:55:12 +00:00
Move from @vercel/postgres to postgres (provider-agnostic) (#989)
* Postgres * fix * fix * prettier-fix --------- Co-authored-by: Delba de Oliveira <32464864+delbaoliveira@users.noreply.github.com>
This commit is contained in:
@@ -1,15 +1,17 @@
|
||||
import NextAuth from 'next-auth';
|
||||
import Credentials from 'next-auth/providers/credentials';
|
||||
import bcrypt from 'bcrypt';
|
||||
import { sql } from '@vercel/postgres';
|
||||
import postgres from 'postgres';
|
||||
import { z } from 'zod';
|
||||
import type { User } from '@/app/lib/definitions';
|
||||
import { authConfig } from './auth.config';
|
||||
|
||||
const sql = postgres(process.env.POSTGRES_URL!, { ssl: 'require' });
|
||||
|
||||
async function getUser(email: string): Promise<User | undefined> {
|
||||
try {
|
||||
const user = await sql<User>`SELECT * FROM users WHERE email=${email}`;
|
||||
return user.rows[0];
|
||||
const user = await sql<User[]>`SELECT * FROM users WHERE email=${email}`;
|
||||
return user[0];
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch user:', error);
|
||||
throw new Error('Failed to fetch user.');
|
||||
|
||||
Reference in New Issue
Block a user