fix: Guest account can't access alerts properly (#875)

# PR Checklist
- [ ] Have you checked if it works normally in all models? *Ignore this
if it doesn't use models.*
- [x] Have you checked if it works normally in all web, local, and node
hosted versions? If it doesn't, have you blocked it in those versions?
- [x] Have you added type definitions?

# Description


![image](https://github.com/user-attachments/assets/55d468e2-4af7-42bb-81db-a13208a2be1a)

When an user is not logged in and anytime any dialog is about to open,
undefined property access of `message` event happens, opening error
dialog, which causes another undefined property access, and so forth.
This does not stop so it blocks even log in itself.

This PR mitigates it by simply converting those accesses to optional
chaining.
This commit is contained in:
kwaroran
2025-05-25 22:48:06 +09:00
committed by GitHub
2 changed files with 3 additions and 3 deletions

View File

@@ -63,7 +63,7 @@
<svelte:window onmessage={async (e) => {
if(e.origin.startsWith("https://sv.risuai.xyz") || e.origin.startsWith("http://127.0.0.1") || e.origin === window.location.origin){
if(e.data.msg.data.vaild && $alertStore.type === 'login'){
if(e.data.msg?.data?.vaild && $alertStore.type === 'login'){
$alertStore = {
type: 'none',
msg: JSON.stringify(e.data.msg)

View File

@@ -20,7 +20,7 @@
<svelte:window onmessage={async (e) => {
if(e.origin.startsWith("https://sv.risuai.xyz") || e.origin.startsWith("http://127.0.0.1") || e.origin === window.location.origin){
if(e.data.msg.type === 'drive'){
if(e.data.msg?.type === 'drive'){
await loadRisuAccountData()
DBState.db.account.data.refresh_token = e.data.msg.data.refresh_token
DBState.db.account.data.access_token = e.data.msg.data.access_token
@@ -28,7 +28,7 @@
await saveRisuAccountData()
popup.close()
}
else if(e.data.msg.data.vaild){
else if(e.data.msg?.data.vaild){
openIframe = false
DBState.db.account = {
id: e.data.msg.id,