@@ -101,7 +101,8 @@ ipcMain.handle('login-microsoft', async () => {
101
101
// Extract necessary data from the Minecraft profile
102
102
const accountData = {
103
103
uuid : minecraftProfile . profile . id ,
104
- name : minecraftProfile . profile . name
104
+ name : minecraftProfile . profile . name ,
105
+ refreshToken : xbox . save ( ) // Save refresh token instead of access token
105
106
} ;
106
107
107
108
// Save account data - ensure directory exists first
@@ -138,7 +139,11 @@ ipcMain.handle('login-cracked', async () => {
138
139
const uuid = uuidv4 ( ) ;
139
140
const name = "dev" ;
140
141
141
- const accountData = { uuid, name } ;
142
+ const accountData = {
143
+ uuid,
144
+ name,
145
+ refreshToken : null // Cracked accounts don't have refresh tokens
146
+ } ;
142
147
143
148
// Save account data - ensure directory exists first
144
149
const accountsDirectory = path . dirname ( INSTALL_DIR ) ;
@@ -158,6 +163,33 @@ ipcMain.handle('launch-minecraft', async (event, { uuid, name }) => {
158
163
try {
159
164
const minecraftStarter = new MinecraftStarter ( ) ;
160
165
166
+ // Get fresh access token if this is a Microsoft account
167
+ let accessToken = null ;
168
+ const accountsPath = path . join ( path . dirname ( INSTALL_DIR ) , 'accounts.json' ) ;
169
+
170
+ if ( fs . existsSync ( accountsPath ) ) {
171
+ try {
172
+ const accountData = JSON . parse ( fs . readFileSync ( accountsPath , 'utf8' ) ) ;
173
+
174
+ // Check if this is a Microsoft account with a refresh token
175
+ if ( accountData . refreshToken ) {
176
+ try {
177
+ // Use refresh token to get fresh access token
178
+ const authManager = new Auth ( "select_account" ) ;
179
+ const xbox = await authManager . refresh ( accountData . refreshToken ) ;
180
+ const minecraftProfile = await xbox . getMinecraft ( ) ;
181
+ accessToken = minecraftProfile . access_token ;
182
+ console . log ( 'Got fresh access token using refresh token' ) ;
183
+ } catch ( error ) {
184
+ console . warn ( 'Failed to refresh access token, launching in offline mode:' , error ) ;
185
+ // Continue without token - will work for offline servers
186
+ }
187
+ }
188
+ } catch ( error ) {
189
+ console . warn ( 'Could not load account data:' , error ) ;
190
+ }
191
+ }
192
+
161
193
// Check if BlitzClient directory exists
162
194
const blitzClientPath = path . dirname ( INSTALL_DIR ) ;
163
195
const minecraftPath = path . join ( blitzClientPath , 'minecraft' ) ;
@@ -177,7 +209,7 @@ ipcMain.handle('launch-minecraft', async (event, { uuid, name }) => {
177
209
}
178
210
179
211
// Launch Minecraft
180
- const minecraftProcess = minecraftStarter . run ( uuid , name ) ;
212
+ const minecraftProcess = minecraftStarter . run ( uuid , name , accessToken ) ;
181
213
182
214
// If minecraft directory doesn't exist, download mods after startup
183
215
if ( ! fs . existsSync ( minecraftPath ) ) {
0 commit comments