Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: muse login #677

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading