Refactoring Provider setup of Google Auth
This commit is contained in:
parent
50b0fca034
commit
44d668d7af
@ -67,8 +67,6 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- Rest of the component markup remains unchanged -->
|
|
||||||
|
|
||||||
<div class="grid w-full h-full" style="display: grid; {componentsData.layout || ''}">
|
<div class="grid w-full h-full" style="display: grid; {componentsData.layout || ''}">
|
||||||
{#each componentsData.children as component (component.id)}
|
{#each componentsData.children as component (component.id)}
|
||||||
{#await getComponent(component.componentName) then Component}
|
{#await getComponent(component.componentName) then Component}
|
||||||
|
@ -1,23 +1,15 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount, tick } from 'svelte';
|
import { onMount, tick } from 'svelte';
|
||||||
import {
|
import { isSignInRedirect, getProviderFromUrl } from '@lit-protocol/lit-auth-client';
|
||||||
LitAuthClient,
|
|
||||||
BaseProvider,
|
|
||||||
GoogleProvider,
|
|
||||||
isSignInRedirect,
|
|
||||||
getProviderFromUrl
|
|
||||||
} from '@lit-protocol/lit-auth-client';
|
|
||||||
import { LitNodeClient } from '@lit-protocol/lit-node-client';
|
|
||||||
import { IRelayPKP } from '@lit-protocol/types';
|
import { IRelayPKP } from '@lit-protocol/types';
|
||||||
import { ProviderType } from '@lit-protocol/constants';
|
import { ProviderType } from '@lit-protocol/constants';
|
||||||
import { LitAccessControlConditionResource, LitAbility } from '@lit-protocol/auth-helpers';
|
import { LitAccessControlConditionResource, LitAbility } from '@lit-protocol/auth-helpers';
|
||||||
import { createMessage } from '$lib/services/messages';
|
import { createMessage } from '$lib/services/messages';
|
||||||
|
import { setupLitProvider } from '$lib/services/litProviderSetup.ts';
|
||||||
|
|
||||||
const redirectUri = 'http://localhost:5173/';
|
const redirectUri = 'http://localhost:5173/';
|
||||||
let view = 'sign_in';
|
let view = 'sign_in';
|
||||||
let error;
|
let error;
|
||||||
let litAuthClient;
|
|
||||||
let litNodeClient;
|
|
||||||
let currentProviderType;
|
let currentProviderType;
|
||||||
let authMethod;
|
let authMethod;
|
||||||
let pkps = [];
|
let pkps = [];
|
||||||
@ -25,7 +17,7 @@
|
|||||||
let sessionSigs;
|
let sessionSigs;
|
||||||
let isLoading = false;
|
let isLoading = false;
|
||||||
|
|
||||||
let provider: BaseProvider | undefined;
|
let provider;
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
isLoading = true;
|
isLoading = true;
|
||||||
@ -37,21 +29,8 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
litNodeClient = new LitNodeClient({
|
|
||||||
litNetwork: 'serrano',
|
|
||||||
debug: false
|
|
||||||
});
|
|
||||||
await litNodeClient.connect();
|
|
||||||
|
|
||||||
litAuthClient = new LitAuthClient({
|
|
||||||
litRelayConfig: {
|
|
||||||
relayApiKey: 'test-api-key'
|
|
||||||
},
|
|
||||||
litNodeClient
|
|
||||||
});
|
|
||||||
|
|
||||||
// Globally set the provider during the component's mount
|
// Globally set the provider during the component's mount
|
||||||
provider = litAuthClient.initProvider<GoogleProvider>(ProviderType.Google);
|
provider = await setupLitProvider();
|
||||||
|
|
||||||
console.log('Checking if isSignInRedirect...');
|
console.log('Checking if isSignInRedirect...');
|
||||||
if (!authMethod && isSignInRedirect(redirectUri)) {
|
if (!authMethod && isSignInRedirect(redirectUri)) {
|
||||||
@ -204,7 +183,6 @@
|
|||||||
view = 'CREATING_SESSION';
|
view = 'CREATING_SESSION';
|
||||||
|
|
||||||
const litResource = new LitAccessControlConditionResource('*');
|
const litResource = new LitAccessControlConditionResource('*');
|
||||||
const provider = litAuthClient.getProvider(currentProviderType);
|
|
||||||
sessionSigs = await provider.getSessionSigs({
|
sessionSigs = await provider.getSessionSigs({
|
||||||
pkpPublicKey: pkp.publicKey,
|
pkpPublicKey: pkp.publicKey,
|
||||||
authMethod,
|
authMethod,
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
<script>
|
<script>
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import { connectWallet } from '$lib/services/wallet/wallet';
|
import { connectWallet } from '$lib/services/wallet/wallet';
|
||||||
|
|
||||||
import { getComponentStore } from '$lib/stores/componentStores.ts';
|
import { getComponentStore } from '$lib/stores/componentStores.ts';
|
||||||
|
|
||||||
// please abstract this.
|
// please abstract this.
|
||||||
export let id;
|
export let id;
|
||||||
const store = getComponentStore(id);
|
const store = getComponentStore(id);
|
||||||
|
|
||||||
let pkpWallet = null;
|
export let pkpWallet = null;
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
pkpWallet = await connectWallet($store.pkpPubKey, $store.rpcURL);
|
pkpWallet = await connectWallet($store.pkpPubKey, $store.rpcURL);
|
||||||
|
30
src/lib/services/litProviderSetup.ts
Normal file
30
src/lib/services/litProviderSetup.ts
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
// litProviderSetup.ts
|
||||||
|
|
||||||
|
import {
|
||||||
|
LitAuthClient,
|
||||||
|
GoogleProvider,
|
||||||
|
BaseProvider,
|
||||||
|
} from '@lit-protocol/lit-auth-client';
|
||||||
|
import { ProviderType } from '@lit-protocol/constants';
|
||||||
|
import { LitNodeClient } from '@lit-protocol/lit-node-client';
|
||||||
|
|
||||||
|
let provider: BaseProvider | undefined;
|
||||||
|
|
||||||
|
export async function setupLitProvider() {
|
||||||
|
const litNodeClient = new LitNodeClient({
|
||||||
|
litNetwork: 'serrano',
|
||||||
|
debug: false
|
||||||
|
});
|
||||||
|
await litNodeClient.connect();
|
||||||
|
|
||||||
|
const litAuthClient = new LitAuthClient({
|
||||||
|
litRelayConfig: {
|
||||||
|
relayApiKey: 'test-api-key'
|
||||||
|
},
|
||||||
|
litNodeClient
|
||||||
|
});
|
||||||
|
|
||||||
|
provider = litAuthClient.initProvider<GoogleProvider>(ProviderType.Google);
|
||||||
|
|
||||||
|
return provider;
|
||||||
|
}
|
@ -81,7 +81,7 @@ export function initProvider(data: ProviderData) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
createMessage({
|
createMessage({
|
||||||
text: 'Provider configuration created and autoConnect enabled...',
|
text: 'Chain Provider configuration created and autoConnect enabled...',
|
||||||
sender: '$lib/services/provider.ts',
|
sender: '$lib/services/provider.ts',
|
||||||
type: 'SYSTEM'
|
type: 'SYSTEM'
|
||||||
});
|
});
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
import { LitAuthClient, BaseProvider, GoogleProvider, ProviderType } from '@lit-protocol/lit-auth-client';
|
|
||||||
|
|
||||||
export function initializeProvider(litAuthClient: typeof LitAuthClient): BaseProvider {
|
|
||||||
return litAuthClient.initProvider<GoogleProvider>(ProviderType.Google);
|
|
||||||
}
|
|
@ -4,15 +4,16 @@
|
|||||||
let componentsData = {
|
let componentsData = {
|
||||||
layout: `
|
layout: `
|
||||||
grid-template-areas:
|
grid-template-areas:
|
||||||
|
"auth",
|
||||||
"login",
|
"login",
|
||||||
"play"
|
"play"
|
||||||
grid-template-rows: 1fr 1fr;
|
grid-template-rows: auto 1fr 1fr;
|
||||||
`,
|
`,
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
id: 'login1',
|
id: 'authsig',
|
||||||
componentName: 'GoogleAuth',
|
componentName: 'AuthSig',
|
||||||
slot: 'login'
|
slot: 'auth'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'wallet1',
|
id: 'wallet1',
|
||||||
@ -23,6 +24,11 @@
|
|||||||
pkpPubKey:
|
pkpPubKey:
|
||||||
'046da3ba67065fd1e2726242ca01cd4601524893f4aa4b0042578fa6cbec28fa8c9a28eb9f7893932fc09717edc9e1db57e157a21eed346247c1db5a722a01f571'
|
'046da3ba67065fd1e2726242ca01cd4601524893f4aa4b0042578fa6cbec28fa8c9a28eb9f7893932fc09717edc9e1db57e157a21eed346247c1db5a722a01f571'
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'login1',
|
||||||
|
componentName: 'GoogleAuth',
|
||||||
|
slot: 'login'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user