mirror of
https://github.com/dreamhunter2333/cloudflare_temp_email.git
synced 2026-09-04 23:17:34 +08:00
fix: add localStorage fallback for OAuth2 session state on mobile browsers (#900)
* fix: add localStorage fallback for OAuth2 session state on mobile browsers Some mobile browsers (Safari ITP, WebViews) lose sessionStorage during cross-origin OAuth2 redirects. Add localStorage fallback via computed wrapper that dual-writes on set and reads sessionStorage-first on get. Also cleanup state in finally block to ensure one-time consumption. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: i18n for 'code not found' in OAuth2 callback Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
eeea512ab1
commit
6c58cd3c2e
@@ -112,8 +112,18 @@ export const useGlobalState = createGlobalState(
|
|||||||
);
|
);
|
||||||
const telegramApp = ref(window.Telegram?.WebApp || {});
|
const telegramApp = ref(window.Telegram?.WebApp || {});
|
||||||
const isTelegram = ref(!!window.Telegram?.WebApp?.initData);
|
const isTelegram = ref(!!window.Telegram?.WebApp?.initData);
|
||||||
const userOauth2SessionState = useSessionStorage('userOauth2SessionState', '');
|
const _oauth2StateSession = useSessionStorage('userOauth2SessionState', '');
|
||||||
const userOauth2SessionClientID = useSessionStorage('userOauth2SessionClientID', '');
|
const _oauth2StateFallback = useStorage('userOauth2SessionState_fb', '');
|
||||||
|
const userOauth2SessionState = computed({
|
||||||
|
get: () => _oauth2StateSession.value || _oauth2StateFallback.value,
|
||||||
|
set: (v) => { _oauth2StateSession.value = v; _oauth2StateFallback.value = v; }
|
||||||
|
});
|
||||||
|
const _oauth2ClientIDSession = useSessionStorage('userOauth2SessionClientID', '');
|
||||||
|
const _oauth2ClientIDFallback = useStorage('userOauth2SessionClientID_fb', '');
|
||||||
|
const userOauth2SessionClientID = computed({
|
||||||
|
get: () => _oauth2ClientIDSession.value || _oauth2ClientIDFallback.value,
|
||||||
|
set: (v) => { _oauth2ClientIDSession.value = v; _oauth2ClientIDFallback.value = v; }
|
||||||
|
});
|
||||||
const browserFingerprint = ref('');
|
const browserFingerprint = ref('');
|
||||||
return {
|
return {
|
||||||
isDark,
|
isDark,
|
||||||
|
|||||||
@@ -19,28 +19,30 @@ const { t } = useI18n({
|
|||||||
en: {
|
en: {
|
||||||
logging: 'Logging in...',
|
logging: 'Logging in...',
|
||||||
stateNotMatch: 'state not match',
|
stateNotMatch: 'state not match',
|
||||||
|
codeNotFound: 'code not found',
|
||||||
},
|
},
|
||||||
zh: {
|
zh: {
|
||||||
logging: '登录中...',
|
logging: '登录中...',
|
||||||
stateNotMatch: 'state 不匹配',
|
stateNotMatch: 'state 不匹配',
|
||||||
|
codeNotFound: '未找到授权码',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
const state = route.query.state;
|
|
||||||
if (state != userOauth2SessionState.value) {
|
|
||||||
console.error('state not match');
|
|
||||||
message.error(t('stateNotMatch'));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const code = route.query.code;
|
|
||||||
if (!code) {
|
|
||||||
console.error('code not found');
|
|
||||||
message.error('code not found');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
|
const state = route.query.state;
|
||||||
|
if (state != userOauth2SessionState.value) {
|
||||||
|
console.error('state not match');
|
||||||
|
message.error(t('stateNotMatch'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const code = route.query.code;
|
||||||
|
if (!code) {
|
||||||
|
console.error('code not found');
|
||||||
|
message.error(t('codeNotFound'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
const res = await api.fetch(`/user_api/oauth2/callback`, {
|
const res = await api.fetch(`/user_api/oauth2/callback`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
@@ -53,6 +55,9 @@ onMounted(async () => {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
message.error(error.message || 'error');
|
message.error(error.message || 'error');
|
||||||
|
} finally {
|
||||||
|
userOauth2SessionState.value = '';
|
||||||
|
userOauth2SessionClientID.value = '';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user