autologin
This commit is contained in:
@@ -53,6 +53,7 @@ export class User {
|
||||
|
||||
accessToken?: string;
|
||||
refreshToken?: string;
|
||||
session_key?: string;
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
@@ -62,10 +63,10 @@ export class UserRepository extends Repository<User> {
|
||||
}
|
||||
|
||||
findByUsername(username: string): Promise<User> {
|
||||
return this.findOne({where: { username }, relations: ['role']});
|
||||
return this.findOne({ where: { username }, relations: ['role'] });
|
||||
}
|
||||
|
||||
findById(id: string): Promise<User> {
|
||||
return this.findOne({where: { id }, relations: ['role']});
|
||||
return this.findOne({ where: { id }, relations: ['role'] });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -254,6 +254,11 @@ export class UsersService {
|
||||
const refresh = this.createRefreshToken(user);
|
||||
user.accessToken = access;
|
||||
user.refreshToken = refresh;
|
||||
const s = this.sessionRepo.create({
|
||||
user,
|
||||
});
|
||||
const session = await this.sessionRepo.save(s);
|
||||
user.session_key = session.id;
|
||||
return user;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,12 +39,19 @@ export class LoginComponent {
|
||||
|
||||
|
||||
private handleLoginData(data: any) {
|
||||
console.log(data)
|
||||
if (data["session_key"]) {
|
||||
localStorage.setItem('auth_session_key', data.session_key)
|
||||
}
|
||||
if (data["code"] != null) {
|
||||
if (this.redirectUri) {
|
||||
location.href = this.redirectUri + "?code=" + data["code"];
|
||||
}
|
||||
} else if (data["id"] != null) {
|
||||
}
|
||||
|
||||
if (data["id"] != null) {
|
||||
this.userService.user = data as User;
|
||||
|
||||
this.navigateToDashboard();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,4 +6,5 @@ export interface User {
|
||||
createdAt: string;
|
||||
accessToken: string;
|
||||
refreshToken: string;
|
||||
code?: string;
|
||||
}
|
||||
Reference in New Issue
Block a user