mirror of
https://github.com/FranP-code/create-better-t-stack.git
synced 2025-10-12 23:52:15 +00:00
add mongoose orm to the stack builder (#191)
This commit is contained in:
committed by
GitHub
parent
946f3eb421
commit
437cf9a45a
@@ -58,6 +58,31 @@ export const auth = betterAuth({
|
||||
});
|
||||
{{/if}}
|
||||
|
||||
{{#if (eq orm "mongoose")}}
|
||||
import { betterAuth } from "better-auth";
|
||||
import { mongodbAdapter } from "better-auth/adapters/mongodb";
|
||||
{{#if (includes frontend "native")}}
|
||||
import { expo } from "@better-auth/expo";
|
||||
{{/if}}
|
||||
import { client } from "../db";
|
||||
|
||||
export const auth = betterAuth({
|
||||
database: mongodbAdapter(client.db()),
|
||||
trustedOrigins: [
|
||||
process.env.CORS_ORIGIN || "",{{#if (includes frontend "native")}}
|
||||
"my-better-t-app://",{{/if}}
|
||||
],
|
||||
emailAndPassword: {
|
||||
enabled: true,
|
||||
}
|
||||
|
||||
{{~#if (includes frontend "native")}}
|
||||
,
|
||||
plugins: [expo()]
|
||||
{{/if~}}
|
||||
});
|
||||
{{/if}}
|
||||
|
||||
{{#if (eq orm "none")}}
|
||||
import { betterAuth } from "better-auth";
|
||||
{{#if (includes frontend "native")}}
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
import mongoose from 'mongoose';
|
||||
|
||||
const { Schema, model } = mongoose;
|
||||
|
||||
const userSchema = new Schema(
|
||||
{
|
||||
_id: { type: String },
|
||||
name: { type: String, required: true },
|
||||
email: { type: String, required: true, unique: true },
|
||||
emailVerified: { type: Boolean, required: true },
|
||||
image: { type: String },
|
||||
createdAt: { type: Date, required: true },
|
||||
updatedAt: { type: Date, required: true },
|
||||
},
|
||||
{ collection: 'user' }
|
||||
);
|
||||
|
||||
const sessionSchema = new Schema(
|
||||
{
|
||||
_id: { type: String },
|
||||
expiresAt: { type: Date, required: true },
|
||||
token: { type: String, required: true, unique: true },
|
||||
createdAt: { type: Date, required: true },
|
||||
updatedAt: { type: Date, required: true },
|
||||
ipAddress: { type: String },
|
||||
userAgent: { type: String },
|
||||
userId: { type: String, ref: 'User', required: true },
|
||||
},
|
||||
{ collection: 'session' }
|
||||
);
|
||||
|
||||
const accountSchema = new Schema(
|
||||
{
|
||||
_id: { type: String },
|
||||
accountId: { type: String, required: true },
|
||||
providerId: { type: String, required: true },
|
||||
userId: { type: String, ref: 'User', required: true },
|
||||
accessToken: { type: String },
|
||||
refreshToken: { type: String },
|
||||
idToken: { type: String },
|
||||
accessTokenExpiresAt: { type: Date },
|
||||
refreshTokenExpiresAt: { type: Date },
|
||||
scope: { type: String },
|
||||
password: { type: String },
|
||||
createdAt: { type: Date, required: true },
|
||||
updatedAt: { type: Date, required: true },
|
||||
},
|
||||
{ collection: 'account' }
|
||||
);
|
||||
|
||||
const verificationSchema = new Schema(
|
||||
{
|
||||
_id: { type: String },
|
||||
identifier: { type: String, required: true },
|
||||
value: { type: String, required: true },
|
||||
expiresAt: { type: Date, required: true },
|
||||
createdAt: { type: Date },
|
||||
updatedAt: { type: Date },
|
||||
},
|
||||
{ collection: 'verification' }
|
||||
);
|
||||
|
||||
const User = model('User', userSchema);
|
||||
const Session = model('Session', sessionSchema);
|
||||
const Account = model('Account', accountSchema);
|
||||
const Verification = model('Verification', verificationSchema);
|
||||
|
||||
export { User, Session, Account, Verification };
|
||||
Reference in New Issue
Block a user