Skip to content

Commit

Permalink
Merge pull request #677 from lovegaoshi/dev
Browse files Browse the repository at this point in the history
fix: muse login
  • Loading branch information
lovegaoshi authored Dec 4, 2024
2 parents 9b9ec79 + 5b7f9f5 commit 7fbbe63
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/components/login/google/YTM.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,21 @@ import { StorageKeys } from '@enums/Storage';
import { User, UseYTMLogin } from './useYTMLogin';
import useCollapsible from '../useCollapsible';
import { initMuse } from '@utils/muse';
import logger from '@utils/Logger';

const jsCode = 'window.ReactNativeWebView.postMessage(document.cookie)';

const clearCookies = () => {
saveItem(StorageKeys.YTMCOOKIES, null);
initMuse();
};

const checkYTM = async () => {
await initMuse();
get_current_user().then(console.log).catch(console.log);
};

const Login = () => {
const Login = ({ refresh }: { refresh: () => void }) => {
const { t } = useTranslation();
const [webView, _setWebView] = useState(false);
const [cookies, setCookies] = useState<string[]>([]);
Expand All @@ -51,7 +53,13 @@ const Login = () => {
value,
});
});
saveItem(StorageKeys.YTMCOOKIES, cookies.join('; '));
if (cookies.length === 0) {
logger.error('[YTM] failed to login, as cookie length is 0.');
return;
}
saveItem(StorageKeys.YTMCOOKIES, cookies.join('; '))
.then(() => initMuse().then(refresh))
.catch(logger.error);
return true;
}
return false;
Expand Down Expand Up @@ -113,7 +121,7 @@ interface Props {
ytmLogin: UseYTMLogin;
}
const Explore = ({ ytmLogin }: Props) => {
const { user, clear, initialized, init } = ytmLogin;
const { user, clear, initialized, init, refresh } = ytmLogin;

useEffect(() => {
init();
Expand All @@ -131,7 +139,7 @@ const Explore = ({ ytmLogin }: Props) => {
}}
/>
) : (
<Login />
<Login refresh={refresh} />
);
};

Expand Down

0 comments on commit 7fbbe63

Please sign in to comment.