Skip to content

Commit e7bede9

Browse files
authored
Merge pull request #27 from agentlabs-inc/feat/members-oauth
Feat/members oauth
2 parents 9eef431 + 06d217c commit e7bede9

File tree

73 files changed

+1267
-1466
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+1267
-1466
lines changed

.env.example

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ EMAIL_SENDER_NAME=
4141
USERS_OAUTH_GOOGLE_CLIENT_ID=
4242
USERS_OAUTH_GOOGLE_CLIENT_ID=
4343

44+
# You don't want to touch that if you don't work at AgentLabs.
45+
MEMBERS_DEMO_OAUTH_GOOGLE_CLIENT_ID=
46+
MEMBERS_DEMO_OAUTH_GOOGLE_CLIENT_SECRET=
47+
4448
# ----------------------
4549
# - Image configuration -
4650
# Unless you really know what you are doing you most likely do not want to

console/src/lib/components/common/multi-select/MultiSelect.svelte

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
import type { MultiSelectItem } from "$lib/components/common/multi-select/types";
33
import { Icon } from "svelte-hero-icons";
44
import { createEventDispatcher } from "svelte";
5+
import Typography from "$lib/components/common/typography/Typography.svelte";
56
67
const dispatch = createEventDispatcher<{ change: MultiSelectItem[] }>();
78
export let items: MultiSelectItem[] = [];
89
910
let selectedItems: Record<string, MultiSelectItem> = {};
1011
1112
const handleSelect = (item: MultiSelectItem) => {
13+
if (item.disabled) return;
14+
1215
if (selectedItems[item.id]) {
1316
delete selectedItems[item.id];
1417
selectedItems = { ...selectedItems };
@@ -26,7 +29,9 @@
2629
<button
2730
id={item.id}
2831
on:click={() => handleSelect(item)}
29-
class="antialiased border rounded-md p-3 border-stroke-base dark:border-stroke-base-dark flex items-center justify-left gap-3 text-body-base dark:text-body-base-dark hover:bg-background-accent dark:hover:bg-background-accent-dark cursor-pointer {selectedItems[
32+
class="{item.disabled
33+
? 'opacity-60 bg-background-accent dark:bg-background-accent-dark'
34+
: ''} antialiased border rounded-md p-3 border-stroke-base dark:border-stroke-base-dark flex items-center justify-left gap-3 text-body-base dark:text-body-base-dark hover:bg-background-accent dark:hover:bg-background-accent-dark cursor-pointer {selectedItems[
3035
item.id
3136
]
3237
? 'border border-stroke-info dark:border-stroke-info-dark'
@@ -44,6 +49,9 @@
4449
</div>
4550
{/if}
4651
<span>{item.label}</span>
52+
{#if item.disabledLabel}
53+
<Typography type="label">{item.disabledLabel}</Typography>
54+
{/if}
4755
</button>
4856
{/each}
4957
</div>

console/src/lib/usecases/projects/initProjectAuthMethod.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { AuthMethodsService } from "$lib/services/gen-api";
21
import type { MultiSelectItem } from "$lib/components/common/multi-select/types";
2+
import { AuthMethodsService } from "$lib/services/gen-api";
33

44
export const initProjectAuthMethods = async (
55
projectId: string,
@@ -11,7 +11,7 @@ export const initProjectAuthMethods = async (
1111
projectId,
1212
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
1313
// @ts-ignore
14-
methodTypes: ["PASSWORDLESS_EMAIL"]
14+
methods: methods.map((m) => m.value)
1515
}
1616
});
1717

console/src/lib/utils/unique.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export const unique = <T>(arr: T[]): T[] => {
2-
const set = new Set(arr);
3-
return Array.from(set);
2+
const set = new Set(arr);
3+
return Array.from(set);
44
};

console/src/routes/onboarding/project/[projectId]/auth/+page.svelte

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,40 +23,38 @@
2323
{
2424
id: "passwordless-email",
2525
label: "Passwordless email",
26-
value: "passwordless-email",
26+
value: "PASSWORDLESS_EMAIL",
2727
heroIcon: Envelope
2828
},
2929
{
3030
id: "google",
3131
label: "Google / Gmail",
32-
value: "google",
33-
customIcon: GoogleIcon,
34-
disabled: true,
35-
disabledLabel: "Coming soon"
32+
value: "GOOGLE",
33+
customIcon: GoogleIcon
3634
},
3735
{
3836
id: "github",
3937
label: "Github",
4038
value: "github",
4139
customIcon: GithubIcon,
4240
disabled: true,
43-
disabledLabel: "Coming soon"
41+
disabledLabel: "soon"
4442
},
4543
{
4644
id: "gitlab",
4745
label: "Gitlab",
4846
value: "gitlab",
4947
customIcon: GitlabIcon,
5048
disabled: true,
51-
disabledLabel: "Coming soon"
49+
disabledLabel: "soon"
5250
},
5351
{
5452
id: "microsoft",
55-
label: "Microsoft / Outlook",
53+
label: "Microsoft",
5654
value: "microsoft",
5755
customIcon: MicrosoftIcon,
5856
disabled: true,
59-
disabledLabel: "Coming soon"
57+
disabledLabel: "soon"
6058
}
6159
];
6260

console/src/routes/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const SignInMethods = ["passwordless-email", "google", "github", "gitlab"] as const;
1+
export const SignInMethods = ["PASSWORDLESS_EMAIL", "GOOGLE"] as const;
22
export type SignInMethod = (typeof SignInMethods)[number];
33

44
export type MainLayoutContext = {

docker-compose.dev.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ services:
5050
- EMAIL_SENDER_NAME=${EMAIL_SENDER_NAME}
5151
- USERS_OAUTH_GOOGLE_CLIENT_ID=${USERS_OAUTH_GOOGLE_CLIENT_ID}
5252
- USERS_OAUTH_GOOGLE_CLIENT_SECRET=${USERS_OAUTH_GOOGLE_CLIENT_SECRET}
53+
- MEMBERS_DEMO_OAUTH_GOOGLE_CLIENT_ID=${MEMBERS_DEMO_OAUTH_GOOGLE_CLIENT_ID}
54+
- MEMBERS_DEMO_OAUTH_GOOGLE_CLIENT_SECRET=${MEMBERS_DEMO_OAUTH_GOOGLE_CLIENT_SECRET}
5355
ports:
5456
- ${DEV_SERVER_PORT}:3000
5557
restart: unless-stopped

frontend/package-lock.json

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"eslint-config-prettier": "^8.5.0",
4040
"eslint-plugin-storybook": "^0.6.13",
4141
"eslint-plugin-svelte": "^2.30.0",
42+
"localstorage-slim": "^2.6.0",
4243
"marked": "^9.0.3",
4344
"postcss": "^8.4.29",
4445
"prettier": "^2.8.0",
Lines changed: 11 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,33 @@
11
<script lang="ts">
22
import Button from "$lib/components/common/button/Button.svelte";
33
import type { AuthProvider } from "$lib/components/auth/types";
4+
import { AuthProviderNameMap } from "$lib/components/auth/types";
45
import GoogleIcon from "$lib/components/auth/GoogleIcon.svelte";
56
import GitlabIcon from "$lib/components/auth/GitlabIcon.svelte";
67
import GithubIcon from "$lib/components/auth/GithubIcon.svelte";
7-
import { AgentLabsApp } from "$lib/externals/agentlabs-js-sdk/agentlabs";
8-
import { getAuth, signInWithRedirect } from "$lib/externals/agentlabs-js-sdk/auth";
9-
import GoogleAuthProvider from "$lib/externals/agentlabs-js-sdk/auth-providers/google";
10-
import GitlabAuthProvider from "$lib/externals/agentlabs-js-sdk/auth-providers/gitlab";
11-
import GithubAuthProvider from "$lib/externals/agentlabs-js-sdk/auth-providers/github";
8+
import type { PublicAuthMethodDto } from "$lib/services/gen-api";
9+
import { initSignInWithRedirect } from "$lib/usecases/members/initSignInWithRedirect";
10+
import { mainContextStore } from "$lib/stores/main-context";
1211
1312
export let provider: AuthProvider;
1413
14+
export let authMethod: PublicAuthMethodDto;
15+
1516
let providerCurrentlyLoading: AuthProvider | null = null;
1617
1718
const providerIconMap: Record<
1819
AuthProvider,
1920
typeof GoogleIcon | typeof GitlabIcon | typeof GithubIcon
2021
> = {
21-
google: GoogleIcon,
22-
gitlab: GitlabIcon,
23-
github: GithubIcon
24-
};
25-
26-
const providerNameMap: Record<AuthProvider, string> = {
27-
google: "Google",
28-
gitlab: "Gitlab",
29-
github: "Github"
30-
};
31-
32-
// This will be instantiated in the main layout after fetching project config
33-
const app = new AgentLabsApp({
34-
project: {
35-
id: "",
36-
slug: "something",
37-
name: "something"
38-
},
39-
signInMethods: {
40-
google: {
41-
id: "google",
42-
isEnabled: true,
43-
oauthSettings: {
44-
hasClientSecret: false,
45-
clientId:
46-
"1046622402922-2q425h1v1dmacgg2p4g0bj89f8un67q3.apps.googleusercontent.com"
47-
}
48-
}
49-
}
50-
});
51-
52-
const auth = getAuth(app);
53-
54-
const providerHandlerMap: Record<AuthProvider, () => void> = {
55-
google: () =>
56-
signInWithRedirect(
57-
auth,
58-
new GoogleAuthProvider([], auth.getOAuthSignInMethods().google)
59-
),
60-
gitlab: () => signInWithRedirect(auth, new GitlabAuthProvider([])),
61-
github: () => signInWithRedirect(auth, new GithubAuthProvider([]))
22+
GOOGLE: GoogleIcon,
23+
GITLAB: GitlabIcon,
24+
GITHUB: GithubIcon
6225
};
6326
6427
const handleLogin = () => {
65-
console.log(auth.getOAuthSignInMethods().google);
66-
6728
providerCurrentlyLoading = provider;
6829
69-
providerHandlerMap[provider]();
30+
initSignInWithRedirect(authMethod, $mainContextStore?.publicProjectConfig?.id);
7031
};
7132
</script>
7233

@@ -77,6 +38,6 @@
7738
disabled={providerCurrentlyLoading === provider}>
7839
<div class="flex items-center gap-5">
7940
<svelte:component this={providerIconMap[provider]} />
80-
<span>Continue with {providerNameMap[provider]}</span>
41+
<span>Continue with {AuthProviderNameMap[provider]}</span>
8142
</div>
8243
</Button>
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
1-
export const AuthProviders = ["google", "github", "gitlab"] as const;
1+
export const AuthProviders = ["GOOGLE", "GITHUB", "GITLAB"] as const;
22
export type AuthProvider = (typeof AuthProviders)[number];
3+
4+
export const AuthProviderNameMap: Record<AuthProvider, string> = {
5+
GOOGLE: "Google",
6+
GITHUB: "GitHub",
7+
GITLAB: "GitLab"
8+
} as const;

frontend/src/lib/externals/agentlabs-js-sdk/agentlabs.ts

Lines changed: 0 additions & 54 deletions
This file was deleted.

frontend/src/lib/externals/agentlabs-js-sdk/auth-providers/auth-providers.types.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)