implemented login
This commit is contained in:
@@ -4,7 +4,7 @@ import { z } from 'zod';
|
||||
import { revalidatePath } from 'next/cache';
|
||||
import { redirect } from 'next/navigation';
|
||||
import clientPromise from './mongodb';
|
||||
import { BillAttachment, Bill, BillingLocation } from './db-types';
|
||||
import { BillAttachment, BillingLocation } from './db-types';
|
||||
import { ObjectId } from 'mongodb';
|
||||
|
||||
export type State = {
|
||||
|
||||
12
app/lib/global.d.ts
vendored
12
app/lib/global.d.ts
vendored
@@ -1,8 +1,8 @@
|
||||
import { MongoClient } from "mongodb";
|
||||
|
||||
declare global {
|
||||
namespace globalThis {
|
||||
/** global Mongo Client used in development */
|
||||
var _mongoClientPromise: Promise<MongoClient>
|
||||
}
|
||||
}
|
||||
// declare global {
|
||||
// namespace globalThis {
|
||||
// /** global Mongo Client used in development */
|
||||
// var _mongoClientPromise: Promise<MongoClient>
|
||||
// }
|
||||
// }
|
||||
21
app/lib/loginActions.ts
Normal file
21
app/lib/loginActions.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { signIn } from '@/auth';
|
||||
import { AuthError } from 'next-auth';
|
||||
|
||||
export async function authenticate(
|
||||
prevState: string | undefined,
|
||||
formData: FormData,
|
||||
) {
|
||||
try {
|
||||
await signIn('credentials', formData);
|
||||
} catch (error) {
|
||||
if (error instanceof AuthError) {
|
||||
switch (error.type) {
|
||||
case 'CredentialsSignin':
|
||||
return 'Invalid credentials.';
|
||||
default:
|
||||
return 'Something went wrong.';
|
||||
}
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
import { Client, QueryResult, QueryResultRow } from 'pg';
|
||||
|
||||
const client = new Client({
|
||||
// connectionString: process.env.DATABASE_URL,
|
||||
host: process.env.POSTGRES_HOST,
|
||||
user: process.env.POSTGRES_USER,
|
||||
password: process.env.POSTGRES_PASSWORD,
|
||||
database: process.env.POSTGRES_DB
|
||||
});
|
||||
|
||||
client.connect();
|
||||
|
||||
/** an adapter function which simulates @vercel/postgres `sql` function */
|
||||
export function sql<T extends QueryResultRow>(strings: TemplateStringsArray, ...values: any[]): Promise<QueryResult<T>> {
|
||||
// string values need to be wrapped in single quotes
|
||||
const fixedValues = values.map((value) => {
|
||||
if (typeof value === 'string') {
|
||||
return `'${value}'`;
|
||||
}
|
||||
return value;
|
||||
});
|
||||
|
||||
const query = String.raw(strings, ...fixedValues);
|
||||
return client.query<T>(query);
|
||||
}
|
||||
6
app/lib/types/User.ts
Normal file
6
app/lib/types/User.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export type User = {
|
||||
id: string;
|
||||
name: string;
|
||||
email: string;
|
||||
password: string;
|
||||
};
|
||||
Reference in New Issue
Block a user