Attempting to set up a JWT authentication system using NestJs and SQLite. The code successfully generates the SQLite file, but then throws an error stating "Unable to connect to the database." Upon checking with the SQLite terminal, it became apparent that the tables had not been added as well.
Here is the entity:
import {
BeforeInsert,
Column,
CreateDateColumn,
Entity,
PrimaryGeneratedColumn
} from 'typeorm';
import * as bcrypt from 'bcrypt';
import * as jwt from 'jsonwebtoken';
import {UserRO} from './user.dto';
@Entity('user')
export class UserEntity {
@PrimaryGeneratedColumn(`uuid`)
id: string;
@CreateDateColumn()
created: Date;
@Column({
type: 'text',
unique: true
})
username: string;
@Column('text')
password: string;
@BeforeInsert()
async hashPassword() {
this.password = await bcrypt.hash(this.password, 10);
}
And here is the SQLite DB description from app.module:
@Module({
imports: [TypeOrmModule.forRoot({
type: 'sqlite',
database: 'taskDB',
synchronize: true,
logging: false,
entities: [__dirname + '/../**/*.entity{.ts,.js}'],
}), UserModule],
controllers: [AppController],
providers: [AppService],
})
The terminal output displays the following error message:
(function (exports, require, module, __filename, __dirname) { import {BeforeInsert, Column, CreateDateColumn, Entity, PrimaryGeneratedColumn} from 'typeorm';
[0] ^
[0]
[0] SyntaxError: Unexpected token {
[0] at new Script (vm.js:85:7)
[0] at createScript (vm.js:266:10)
[0] at Object.runInThisContext (vm.js:314:10)
[0] at Module._compile (internal/modules/cjs/loader.js:698:28)
[0] at Object.Module._extensions..js (internal/modules/cjs/loader.js:749:10)
[0] at Module.load (internal/modules/cjs/loader.js:630:32)
[0] at tryModuleLoad (internal/modules/cjs/loader.js:570:12)
[0] at Function.Module._load (internal/modules/cjs/loader.js:562:3)
[0] at Module.require (internal/modules/cjs/loader.js:667:17)
[0] at require (internal/modules/cjs/helpers.js:20:18)