diff --git a/src/lib/profiles.ts b/src/lib/profiles.ts index 8ab0c519f..99f8ebe2a 100644 --- a/src/lib/profiles.ts +++ b/src/lib/profiles.ts @@ -1,3 +1,5 @@ +import { OAuthProvider } from '@appwrite.io/console'; + type Profile = { hasChatLayout: boolean; hasAuth: boolean; @@ -10,6 +12,9 @@ type Profile = { hasFullPageSignup: boolean; defaultProjectName: string; hasChat: boolean; + hasGithubLogin: boolean; + githubLoginProvider?: string; + hasGoogleLogin: boolean; }; export const ConsoleCloudProfile: Profile = { @@ -23,7 +28,10 @@ export const ConsoleCloudProfile: Profile = { hasProjectProgressBars: true, hasFullPageSignup: false, defaultProjectName: 'Appwrite project', - hasChat: false + hasChat: false, + hasGithubLogin: true, + githubLoginProvider: OAuthProvider.Github, + hasGoogleLogin: false }; export const ConsoleSelfhostedProfile: Profile = { @@ -37,7 +45,9 @@ export const ConsoleSelfhostedProfile: Profile = { hasProjectProgressBars: true, hasFullPageSignup: false, defaultProjectName: 'Appwrite project', - hasChat: false + hasChat: false, + hasGithubLogin: false, + hasGoogleLogin: false }; export const StudioProfile: Profile = { @@ -51,5 +61,8 @@ export const StudioProfile: Profile = { hasProjectProgressBars: false, hasFullPageSignup: true, defaultProjectName: 'Imagine project', - hasChat: true + hasChat: true, + hasGithubLogin: true, + githubLoginProvider: 'github2', + hasGoogleLogin: true }; diff --git a/src/routes/(public)/(guest)/login/+page.svelte b/src/routes/(public)/(guest)/login/+page.svelte index c8a4bdb5c..9ad34fc01 100644 --- a/src/routes/(public)/(guest)/login/+page.svelte +++ b/src/routes/(public)/(guest)/login/+page.svelte @@ -70,12 +70,36 @@ } } sdk.forConsole.account.createOAuth2Session( - OAuthProvider.Github, + consoleProfile.githubLoginProvider as OAuthProvider, window.location.origin + url, window.location.origin, ['read:user', 'user:email'] ); } + + function onGoogleLogin() { + let url = window.location.origin; + + if (page.url.searchParams) { + const redirect = page.url.searchParams.get('redirect'); + page.url.searchParams.delete('redirect'); + if (redirect) { + url = `${redirect}${page.url.search}`; + } else { + url = `${base}${page.url.search ?? ''}`; + } + } + sdk.forConsole.account.createOAuth2Session( + OAuthProvider.Google, + window.location.origin + url, + window.location.origin, + [ + 'https://www.googleapis.com/auth/userinfo.email', + 'https://www.googleapis.com/auth/userinfo.profile', + 'openid' + ] + ); + } @@ -100,20 +124,29 @@ required={true} bind:value={pass} /> - {#if isCloud} + {#if isCloud && (consoleProfile.hasGithubLogin || consoleProfile.hasGoogleLogin)} or + {/if} + {#if isCloud && consoleProfile.hasGoogleLogin} + + {/if} + {#if isCloud && consoleProfile.hasGithubLogin} {/if} +
Forgot Password?Forgot password? - - + Sign up diff --git a/src/routes/(public)/(guest)/register/+page.svelte b/src/routes/(public)/(guest)/register/+page.svelte index 9ba9053e0..2c3be6384 100644 --- a/src/routes/(public)/(guest)/register/+page.svelte +++ b/src/routes/(public)/(guest)/register/+page.svelte @@ -73,12 +73,25 @@ function onGithubLogin() { sdk.forConsole.account.createOAuth2Session( - OAuthProvider.Github, + consoleProfile.githubLoginProvider as OAuthProvider, window.location.origin, window.location.origin, ['read:user', 'user:email'] ); } + + function onGoogleLogin() { + sdk.forConsole.account.createOAuth2Session( + OAuthProvider.Google, + window.location.origin, + window.location.origin, + [ + 'https://www.googleapis.com/auth/userinfo.email', + 'https://www.googleapis.com/auth/userinfo.profile', + 'openid' + ] + ); + } @@ -121,9 +134,18 @@ target="_blank" rel="noopener noreferrer">General Terms of Use. +
- {#if isCloud} + {#if isCloud && (consoleProfile.hasGithubLogin || consoleProfile.hasGoogleLogin)} or + {/if} + {#if isCloud && consoleProfile.hasGoogleLogin} + + {/if} + {#if isCloud && consoleProfile.hasGithubLogin}