-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] OAuth Login not working on Firefox (#20722)
Co-authored-by: Guilherme Gazzo <guilhermegazzo@gmail.com>
- Loading branch information
1 parent
78b972b
commit 35171fa
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Meteor } from 'meteor/meteor'; | ||
import { OAuth } from 'meteor/oauth'; | ||
import { Reload } from 'meteor/reload'; | ||
|
||
// TODO: This is a nasty workaround and should be removed as soon as possible | ||
// Firefox is losing the sessionStorage data (v >= 79.0) after the redirect | ||
|
||
if (navigator.userAgent.indexOf('Firefox') !== -1) { | ||
const KEY_NAME = 'Swapped_Storage_Workaround'; | ||
|
||
OAuth.saveDataForRedirect = (loginService, credentialToken) => { | ||
Meteor._localStorage.setItem(KEY_NAME, JSON.stringify({ loginService, credentialToken })); | ||
Reload._migrate(null, { immediateMigration: true }); | ||
}; | ||
|
||
OAuth.getDataAfterRedirect = () => { | ||
let migrationData = Meteor._localStorage.getItem(KEY_NAME); | ||
Meteor._localStorage.removeItem(KEY_NAME); | ||
try { | ||
migrationData = JSON.parse(migrationData); | ||
} catch (error) { | ||
migrationData = null; | ||
} | ||
|
||
if (! (migrationData && migrationData.credentialToken)) { return null; } | ||
|
||
const { credentialToken } = migrationData; | ||
const key = OAuth._storageTokenPrefix + credentialToken; | ||
let credentialSecret; | ||
try { | ||
credentialSecret = sessionStorage.getItem(key); | ||
sessionStorage.removeItem(key); | ||
} catch (e) { | ||
Meteor._debug('error retrieving credentialSecret', e); | ||
} | ||
return { | ||
loginService: migrationData.loginService, | ||
credentialToken, | ||
credentialSecret, | ||
}; | ||
}; | ||
} |