adding route for sign up and such

This commit is contained in:
talksik
2022-03-17 21:42:03 -04:00
parent 444c116f1b
commit 4b2a7f7043
14 changed files with 120 additions and 68 deletions
+1 -1
View File
@@ -9,7 +9,7 @@ export const collections: { users?: mongoDB.Collection } = {};
// Initialize Connection
export async function connectToDatabase() {
const client: mongoDB.MongoClient = new mongoDB.MongoClient(
process.env.DB_CONN_STRING!
"mongodb+srv://default:[email protected]/default?retryWrites=true&w=majority"
);
await client.connect();
+23
View File
@@ -0,0 +1,23 @@
import { ObjectId } from "mongodb";
import { User } from "@nirvana/core/models";
import { collections } from "./database.service";
export class UserService {
static async getUserById(userId: string) {
const query = { _id: new ObjectId(userId) };
return (await collections.users?.findOne(query)) as unknown as User;
}
static async createUserIfNotExists(newUser: User) {
return await collections.users?.insertOne(newUser);
}
static async getGoogleUserInfoWithAccessToken(accessToken: string) {
return await (
await fetch(
`https://www.googleapis.com/oauth2/v1/userinfo?access_token=${accessToken}`
)
).json();
}
}