diff --git a/idp/src/model/user.entity.ts b/idp/src/model/user.entity.ts index a668595..b804e7e 100644 --- a/idp/src/model/user.entity.ts +++ b/idp/src/model/user.entity.ts @@ -53,6 +53,7 @@ export class User { accessToken?: string; refreshToken?: string; + session_key?: string; } @Injectable() @@ -62,10 +63,10 @@ export class UserRepository extends Repository { } findByUsername(username: string): Promise { - return this.findOne({where: { username }, relations: ['role']}); + return this.findOne({ where: { username }, relations: ['role'] }); } findById(id: string): Promise { - return this.findOne({where: { id }, relations: ['role']}); + return this.findOne({ where: { id }, relations: ['role'] }); } } diff --git a/idp/src/users/users.service.ts b/idp/src/users/users.service.ts index dc4e33b..3383685 100644 --- a/idp/src/users/users.service.ts +++ b/idp/src/users/users.service.ts @@ -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; } } diff --git a/idp_client/src/app/auth/login/login.component.ts b/idp_client/src/app/auth/login/login.component.ts index 848368b..2eb1194 100644 --- a/idp_client/src/app/auth/login/login.component.ts +++ b/idp_client/src/app/auth/login/login.component.ts @@ -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(); } } diff --git a/idp_client/src/app/model/user.interface.ts b/idp_client/src/app/model/user.interface.ts index 9c6da37..9bb4d67 100644 --- a/idp_client/src/app/model/user.interface.ts +++ b/idp_client/src/app/model/user.interface.ts @@ -6,4 +6,5 @@ export interface User { createdAt: string; accessToken: string; refreshToken: string; + code?: string; } \ No newline at end of file