Skip to content

Commit a5e6a9e

Browse files
committed
feat: add OTP verification and admin credentials to .env.example; refactor user ID handling in controllers and models
1 parent 90aa38d commit a5e6a9e

File tree

5 files changed

+18
-8
lines changed

5 files changed

+18
-8
lines changed

packages/create-tbk-app/src/generators/config.generator.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,16 @@ export async function generateEnvExample(
189189
lines.push('# Response Validation');
190190
lines.push('RESPONSE_VALIDATION=warn # strict | warn | off');
191191

192+
// OTP VERIFICATION
193+
lines.push('# OTP Verification');
194+
lines.push('OTP_VERIFICATION_ENABLED=false');
195+
lines.push('');
196+
197+
// ADMIN EMAIL AND PASSWORD
198+
lines.push('# Admin Email and Password');
199+
lines.push('ADMIN_EMAIL=admin@example.com');
200+
lines.push('');
201+
192202
const filePath = path.join(targetDir, '.env.example');
193203
await writeFile(filePath, lines.join('\n'));
194204
}

packages/create-tbk-app/templates/auth/src/modules/user/user.controller.ts.hbs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {
1212
CreateSuperAdminResponseSchema,
1313
} from './user.schema';
1414
import { createUser, deleteUser, getUsers } from './user.services';
15+
import { Types } from 'mongoose';
1516

1617
export const handleDeleteUser = async (
1718
req: Request<MongoIdSchemaType, unknown>,
@@ -71,7 +72,7 @@ export const handleGetUsers = async (
7172
) => {
7273
const { results, paginatorInfo } = await getUsers(
7374
{
74-
id: req.user.sub,
75+
id: new Types.ObjectId(req.user.sub),
7576
},
7677
req.query,
7778
);

packages/create-tbk-app/templates/auth/src/modules/user/user.model.ts.hbs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ const SocialAccountSchema = new Schema<SocialAccountInfoType>({
2020

2121
const UserSchema: Schema<UserType> = new Schema(
2222
{
23-
_id: { type: String, required: true },
2423
email: { type: String, unique: true, required: true },
2524
avatar: { type: String },
2625
username: { type: String, required: true, unique: true },

src/modules/user/user.controller.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ import config from '../../config/env';
44
import type { ResponseExtended } from '../../types';
55
import { successResponse } from '../../utils/response.utils';
66
import { generateRandomPassword } from '../../utils/otp.utils';
7-
import type {
8-
CreateUserSchemaType,
7+
import type {
8+
CreateUserSchemaType,
99
GetUsersSchemaType,
1010
CreateUserResponseSchema,
1111
GetUsersResponseSchema,
1212
CreateSuperAdminResponseSchema,
1313
} from './user.schema';
1414
import { createUser, deleteUser, getUsers } from './user.services';
15+
import { Types } from 'mongoose';
1516

1617
export const handleDeleteUser = async (
1718
req: Request<MongoIdSchemaType, unknown>,
@@ -71,7 +72,7 @@ export const handleGetUsers = async (
7172
) => {
7273
const { results, paginatorInfo } = await getUsers(
7374
{
74-
id: req.user.sub,
75+
id: new Types.ObjectId(req.user.sub),
7576
},
7677
req.query,
7778
);

src/modules/user/user.model.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ const SocialAccountSchema = new Schema<SocialAccountInfoType>({
2020

2121
const UserSchema: Schema<UserType> = new Schema(
2222
{
23-
_id: { type: String, required: true },
2423
email: { type: String, unique: true, required: true },
2524
avatar: { type: String },
2625
username: { type: String, required: true, unique: true },
@@ -41,9 +40,9 @@ const UserSchema: Schema<UserType> = new Schema(
4140

4241
export interface ISocialAccountDocument
4342
extends SocialAccountInfoType,
44-
Document {}
43+
Document { }
4544

46-
export interface IUserDocument extends Document<string>, UserModelType {}
45+
export interface IUserDocument extends Document<string>, UserModelType { }
4746

4847
const User = mongoose.model<UserType>("User", UserSchema);
4948
export default User;

0 commit comments

Comments
 (0)