Skip to content

Commit 97d8f79

Browse files
committed
fix:worked on generate client token API related workflow
Signed-off-by: shitrerohit <[email protected]>
1 parent ddbfb57 commit 97d8f79

File tree

6 files changed

+19
-11
lines changed

6 files changed

+19
-11
lines changed

apps/organization/src/organization.service.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -723,8 +723,9 @@ export class OrganizationService {
723723
expires: authenticationResult?.expires_in
724724
};
725725

726-
await this.userRepository.updateAccountDetails(accountData).then(async () => {
727-
addSessionDetails = await this.userRepository.createSession(sessionData);
726+
await this.userRepository.updateAccountDetails(accountData).then(async (response) => {
727+
const finalSessionData = { ...sessionData, accountId: response.id };
728+
addSessionDetails = await this.userRepository.createSession(finalSessionData);
728729
});
729730
} else {
730731
const accountData = {
@@ -735,8 +736,9 @@ export class OrganizationService {
735736
type: TokenType.ORG_TOKEN
736737
};
737738

738-
await this.userRepository.addAccountDetails(accountData).then(async () => {
739-
addSessionDetails = await this.userRepository.createSession(sessionData);
739+
await this.userRepository.addAccountDetails(accountData).then(async (response) => {
740+
const finalSessionData = { ...sessionData, accountId: response.id };
741+
addSessionDetails = await this.userRepository.createSession(finalSessionData);
740742
});
741743
}
742744
// Response: add session id as cookies

apps/user/interfaces/user.interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ export interface ISession {
188188
refreshToken?: string;
189189
keycloakUserId?: string;
190190
type?: string;
191+
accountId?: string;
191192
}
192193

193194
export interface ISessionDetails extends ISession {

apps/user/repositories/user.repository.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -678,14 +678,15 @@ export class UserRepository {
678678

679679
async createSession(tokenDetails: ISession): Promise<session> {
680680
try {
681-
const { sessionToken, userId, expires, refreshToken } = tokenDetails;
681+
const { sessionToken, userId, expires, refreshToken, accountId } = tokenDetails;
682682
const sessionResponse = await this.prisma.session.create({
683683
data: {
684684
sessionToken,
685685
expires,
686686
userId,
687687
// eslint-disable-next-line camelcase
688-
refresh_token: refreshToken
688+
refresh_token: refreshToken,
689+
accountId
689690
}
690691
});
691692
return sessionResponse;

apps/user/src/user.service.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -496,8 +496,9 @@ export class UserService {
496496
type: TokenType.USER_TOKEN
497497
};
498498

499-
await this.userRepository.addAccountDetails(accountData).then(async () => {
500-
addSessionDetails = await this.userRepository.createSession(sessionData);
499+
await this.userRepository.addAccountDetails(accountData).then(async (response) => {
500+
const finalSessionData = { ...sessionData, accountId: response.id };
501+
addSessionDetails = await this.userRepository.createSession(finalSessionData);
501502
});
502503
} else {
503504
accountData = {
@@ -507,8 +508,9 @@ export class UserService {
507508
refreshToken: tokenDetails?.refresh_token
508509
};
509510

510-
await this.userRepository.updateAccountDetails(accountData).then(async () => {
511-
addSessionDetails = await this.userRepository.createSession(sessionData);
511+
await this.userRepository.updateAccountDetails(accountData).then(async (response) => {
512+
const finalSessionData = { ...sessionData, accountId: response.id };
513+
addSessionDetails = await this.userRepository.createSession(finalSessionData);
512514
});
513515
}
514516

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- DropIndex
2+
DROP INDEX "session_accountId_key";

libs/prisma-service/prisma/schema.prisma

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ model session {
6666
user user @relation(fields: [userId], references: [id])
6767
createdAt DateTime @default(now())
6868
updatedAt DateTime @updatedAt
69-
accountId String? @unique @db.Uuid
69+
accountId String? @db.Uuid
7070
account account? @relation(fields: [accountId], references:[id])
7171
}
7272

0 commit comments

Comments
 (0)