autologin

This commit is contained in:
Bastian Wagner
2024-09-05 12:35:34 +02:00
parent 8cae6fd555
commit d5850c38b1
4 changed files with 17 additions and 3 deletions

View File

@@ -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'] });
}
}

View File

@@ -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;
}
}

View File

@@ -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();
}
}

View File

@@ -6,4 +6,5 @@ export interface User {
createdAt: string;
accessToken: string;
refreshToken: string;
code?: string;
}