Code now has the following structure:
- app
-- auth
--- auth.quard.ts
--- auth.service.ts
--- user.ts
- home
--- home.component.html
--- home.component.ts
- login
--- login.component.html
--- login.component.ts
- models
--- UserLogin.js
- app.routing.models.ts
- app.components.ts
- app.components.html
- app.models.ts
- config.js
- index.js
Should I install to connect to the database?
npm install express --save
npm install passport --save
npm install passport-local --save
npm install body-parser --save
npm install express-session --save
npm install bcrypt-nodejs --save
npm install express-handlebars --save
I put the getAllUser method in auth / auth.service.ts
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
import { User } from './user';
import {UserLogin} from './models/userLogin.js';
@Injectable()
export class AuthService {
private loggedIn = new BehaviorSubject<boolean>(false);
get isLoggedIn() {
return this.loggedIn.asObservable();
}
constructor(
private router: Router
) {}
login(user: User) {
if (user.userName !== '' && user.password !== '' ) {
this.loggedIn.next(true);
this.router.navigate(['/']);
}
}
getAllUser() {
return UserLogin.findAll();
}
}
but it returns an error message:
Failed to compile.
./src/app/auth/auth.service.ts
Module not found: Error: Can't resolve './models/userLogin.js' in
'C:\myPath\name_project\src\app\auth'
@ ./src/app/auth/auth.service.ts 15:21-53
@ ./src/app/app.module.ts
@ ./src/main.ts
@ multi webpack-dev-server/client?http://0.0.0.0:0 ./src/main.ts
app/models/userLogin.js:
const UserLogin = sequelize.define('user', {
userName: {
type: Sequelize.STRING
},
password: {
type: Sequelize.STRING
},
});
UserLogin.findAll().then(users => {
console.log(users)
});