mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2026-05-19 13:55:40 -04:00
Working Supertokens Callback
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
/* eslint-disable no-restricted-syntax */
|
||||
/* eslint-disable react-hooks/exhaustive-deps */
|
||||
import { useEffect } from 'react';
|
||||
import { NavigateFunction, useNavigate } from 'react-router-dom';
|
||||
import { NavigateFunction, useNavigate, useSearchParams } from 'react-router-dom';
|
||||
import { signInAndUp } from 'supertokens-web-js/recipe/thirdparty';
|
||||
import { toast } from '@sd/ui';
|
||||
|
||||
@@ -44,8 +45,10 @@ async function handleGoogleCallback(navigate: NavigateFunction) {
|
||||
|
||||
export const Component = () => {
|
||||
const navigate = useNavigate();
|
||||
const [query] = useSearchParams();
|
||||
|
||||
useEffect(() => {
|
||||
(window.location as any).__TEMP_URL_PARAMS = query;
|
||||
handleGoogleCallback(navigate);
|
||||
}, []);
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { useSearchParams } from 'react-router-dom';
|
||||
import { WindowHandlerInterface } from 'supertokens-website/utils/windowHandler/types';
|
||||
|
||||
/**
|
||||
@@ -12,20 +13,24 @@ export default function getWindowHandler(original: WindowHandlerInterface): Wind
|
||||
location: {
|
||||
...original.location,
|
||||
getSearch: function () {
|
||||
const currentURL = window.location.href;
|
||||
const firstQuestionMarkIndex = currentURL.indexOf('?');
|
||||
// First try with react-router-dom's useUrlSearchParams
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
|
||||
if (firstQuestionMarkIndex !== -1) {
|
||||
// Return the query string from the url
|
||||
let queryString = currentURL.substring(firstQuestionMarkIndex);
|
||||
const params: URLSearchParams | string = (window.location as any).__TEMP_URL_PARAMS ?? '';
|
||||
return params.toString();
|
||||
// const firstQuestionMarkIndex = currentURL.indexOf('?');
|
||||
|
||||
// Remove any hash
|
||||
if (queryString.includes('#')) {
|
||||
queryString = queryString.split('#')[0] ?? '';
|
||||
}
|
||||
// if (firstQuestionMarkIndex !== -1) {
|
||||
// // Return the query string from the url
|
||||
// let queryString = currentURL.substring(firstQuestionMarkIndex);
|
||||
|
||||
return queryString;
|
||||
}
|
||||
// // Remove any hash
|
||||
// if (queryString.includes('#')) {
|
||||
// queryString = queryString.split('#')[0] ?? '';
|
||||
// }
|
||||
|
||||
// // Return the query string from the url
|
||||
// }
|
||||
|
||||
return '';
|
||||
},
|
||||
|
||||
@@ -10,8 +10,13 @@ export const useDeeplinkEventHandler = () => {
|
||||
|
||||
const url = e.detail.url;
|
||||
if (!url) return;
|
||||
|
||||
navigate(url);
|
||||
// If the URL has search params, we need to navigate to the URL with the search params
|
||||
const [path, search] = url.split('?');
|
||||
if (search) {
|
||||
navigate({ pathname: path, search });
|
||||
} else {
|
||||
navigate(url);
|
||||
}
|
||||
};
|
||||
|
||||
document.addEventListener('deeplink', handler);
|
||||
|
||||
Reference in New Issue
Block a user