Skip to content

Commit

Permalink
fix: improve switch instance
Browse files Browse the repository at this point in the history
  • Loading branch information
abdulhakim2902 committed Feb 4, 2023
1 parent d5988ea commit c5b00d2
Show file tree
Hide file tree
Showing 13 changed files with 243 additions and 288 deletions.
9 changes: 9 additions & 0 deletions pages/api/auth/[...nextauth].ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const createOptions = (req: NextApiRequest) => ({
instanceURL: {label: 'Instance url', type: 'text'},
},
async authorize(credentials) {
// Initialize instance api url
initialize({apiURL: credentials.instanceURL});

if (credentials.anonymous === 'true') {
Expand Down Expand Up @@ -69,6 +70,9 @@ const createOptions = (req: NextApiRequest) => ({
const payload = encryptMessage(data.accessToken, credentials.address);
return credentialToSession(credentials as unknown as SignInCredential, payload);
} catch (error) {
// If failed, use instance url from session
initialize({cookie: req.headers.cookie});

console.log('[api][Auth]', error);
return null;
}
Expand All @@ -92,6 +96,7 @@ const createOptions = (req: NextApiRequest) => ({
async authorize(credentials) {
if (!credentials?.token) throw Error('no token!');

// Initialize instance api url
initialize({apiURL: credentials.instanceURL});

const data = await AuthLinkAPI.loginWithLink(credentials.token);
Expand All @@ -109,6 +114,9 @@ const createOptions = (req: NextApiRequest) => ({
payload,
);
} catch (error) {
// If failed, use instance url from session
initialize({cookie: req.headers.cookie});

console.log('[api][Auth]', error);
return null;
}
Expand Down Expand Up @@ -191,6 +199,7 @@ const createOptions = (req: NextApiRequest) => ({
nonce: user.nonce,
token: user.token,
email: user.email,
instanceURL: user.instanceURL,
};
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/Login/render/Email/LoginByEmail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {Button, TextField, Typography} from '@material-ui/core';

import {useStyles} from './LoginByEmail.style';

import SelectServer from 'components/SelectServer';
import SelectServer from 'src/components/SelectServer';
import {useAuthLinkHook} from 'src/hooks/auth-link.hook';
import {ServerListProps} from 'src/interfaces/server-list';
import i18n from 'src/locale';
Expand Down Expand Up @@ -87,7 +87,7 @@ const LoginByEmail = ({onNext, setSelectedInstance}: LoginByEmailProps) => {
error={error.isError}
helperText={error.isError ? error.message : ''}
/>
<SelectServer onServerSelect={server => toggleSelected(server)} />
<SelectServer onServerSelect={server => toggleSelected(server)} page="login" />
<div className={styles.actionWrapper}>
<Button variant="outlined" color="primary" onClick={handleBack}>
{i18n.t('Login.Email.LoginByEmail.Back')}
Expand Down
6 changes: 3 additions & 3 deletions src/components/Login/render/Options/Options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {InjectedAccountWithMeta} from '@polkadot/extension-inject/types';

import {useStyles} from './Options.style';

import SelectServer from 'components/SelectServer';
import SelectServer from 'src/components/SelectServer';
import {
CoinbaseWalletisabledIcon,
EthereumNetworkIcon,
Expand Down Expand Up @@ -425,7 +425,7 @@ export const Options: React.FC<OptionProps> = props => {
</Grid>
</div>

<SelectServer onServerSelect={server => toggleSelected(server)} />
<SelectServer onServerSelect={server => toggleSelected(server)} page="login" />
<div className={styles.actionWrapper}>
<Button variant="outlined" color="secondary" onClick={() => navigate('/')}>
Back
Expand Down Expand Up @@ -595,7 +595,7 @@ export const Options: React.FC<OptionProps> = props => {
</Grid>
</div>

<SelectServer onServerSelect={server => toggleSelected(server)} />
<SelectServer onServerSelect={server => toggleSelected(server)} page="login" />

<div style={{display: 'flex', flexDirection: 'column', gap: 16}}>
<Button variant="outlined" color="secondary" onClick={() => navigate('/')}>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Menu/Menu.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const useStyles = makeStyles((theme: Theme) =>
padding: '0 30px',
},
backdrop: {
zIndex: theme.zIndex.drawer + 1,
zIndex: theme.zIndex.drawer + 1 + 100,
color: '#fff',
},
}),
Expand Down
Loading

0 comments on commit c5b00d2

Please sign in to comment.