1+ import {
2+ authenticateUserInOpenOpsTables ,
3+ resetUserPassword ,
4+ } from '@openops/common' ;
15import { AppSystemProp , logger , system } from '@openops/server-shared' ;
26import { OrganizationRole , Provider , User } from '@openops/shared' ;
37import { authenticationService } from '../../authentication/basic/authentication-service' ;
@@ -53,6 +57,7 @@ async function ensureUserExists(
5357 `Admin user already exists [${ email } ], updating their password` ,
5458 email ,
5559 ) ;
60+
5661 await upsertAdminPassword ( user , password ) ;
5762 return user ;
5863 }
@@ -73,7 +78,11 @@ async function ensureUserExists(
7378 email ,
7479 ) ;
7580
76- return createAdminUser ( email , password ) ;
81+ user = await createAdminUser ( email , password ) ;
82+ const { token } = await authenticateUserInOpenOpsTables ( email , password ) ;
83+ await resetUserPassword ( email , user . password , token ) ;
84+
85+ return user ;
7786}
7887
7988async function ensureOpenOpsTablesWorkspaceAndDatabaseExist ( ) : Promise < {
@@ -160,7 +169,14 @@ async function upsertAdminPassword(
160169) : Promise < void > {
161170 const email = user . email ;
162171 logger . info ( `Updating password for admin [${ email } ]` , email ) ;
163- await userService . updatePassword ( { id : user . id , newPassword } ) ;
172+
173+ const updatedUser = await userService . updatePassword ( {
174+ id : user . id ,
175+ newPassword,
176+ } ) ;
177+
178+ const { token } = await authenticateUserInOpenOpsTables ( email , newPassword ) ;
179+ await resetUserPassword ( email , updatedUser . password , token ) ;
164180}
165181
166182async function upsertAdminEmail ( user : User , email : string ) : Promise < void > {
0 commit comments