adding route for sign up and such
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user