Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connected account API & Dashboard #279

Draft
wants to merge 29 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
c98dbce
added deprecation
fomalhautb Sep 8, 2024
dd53177
Merge branch 'dev' into connected-account-api
fomalhautb Sep 8, 2024
060cf8d
updated project schema
fomalhautb Sep 8, 2024
0c4194b
improved code structure
fomalhautb Sep 9, 2024
0360737
Merge branch 'dev' into connected-account-api
fomalhautb Sep 10, 2024
daf3bdd
Merge branch 'dev' into connected-account-api
fomalhautb Sep 11, 2024
9190805
fixed project to crud
fomalhautb Sep 11, 2024
2bf957d
Merge branch 'dev' into connected-account-api
fomalhautb Sep 14, 2024
0d7d527
Merge branch 'dev' into connected-account-api
fomalhautb Sep 14, 2024
2448f78
wip
fomalhautb Sep 14, 2024
911f74f
Merge branch 'dev' into connected-account-api
fomalhautb Sep 18, 2024
be2602b
Merge branch 'dev' into connected-account-api
fomalhautb Sep 18, 2024
84e08fd
removed old code
fomalhautb Sep 18, 2024
fe03114
updated stack app
fomalhautb Sep 18, 2024
b72a0c7
fixed boolean type
fomalhautb Sep 18, 2024
fc4cb25
fixed more types
fomalhautb Sep 19, 2024
7b3bf30
project update
fomalhautb Sep 19, 2024
b0c56c4
Merge branch 'dev' into connected-account-api
fomalhautb Sep 20, 2024
9c74986
Merge branch 'dev' into connected-account-api
fomalhautb Sep 25, 2024
410a867
improved error message on yupUnion
fomalhautb Sep 25, 2024
a435d3b
fixed internal project tests
fomalhautb Sep 25, 2024
2981b7f
fixed messages
fomalhautb Sep 25, 2024
cecafe8
Merge branch 'dev' into connected-account-api
fomalhautb Sep 26, 2024
d03699e
fixed bugs, added more tests
fomalhautb Sep 26, 2024
ccca7ee
fixed bugs, updated tests
fomalhautb Sep 26, 2024
0876984
fixed seed script
fomalhautb Sep 26, 2024
93a0050
updated tests
fomalhautb Sep 26, 2024
5c4ef68
fixed bugs and tests
fomalhautb Sep 26, 2024
7b143e1
improved tests
fomalhautb Sep 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Update existing records with new random UUIDs as strings
UPDATE "OAuthProviderConfig" SET "id" = gen_random_uuid()::text;
8 changes: 5 additions & 3 deletions apps/backend/prisma/seed.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { prismaClient } from '@/prisma-client';
import { PrismaClient } from '@prisma/client';
import { typedFromEntries } from '@stackframe/stack-shared/dist/utils/objects';
const prisma = new PrismaClient();


Expand All @@ -15,6 +16,7 @@ async function seed() {
if (oldProject) {
console.log('Internal project already exists, skipping its creation');
} else {
const oauthConfigs = typedFromEntries((['github', 'spotify', 'google', 'microsoft'] as const).map((id) => [id, crypto.randomUUID()]));
await prismaClient.$transaction(async (tx) => {
const createdProject = await prisma.project.upsert({
where: {
Expand All @@ -39,7 +41,7 @@ async function seed() {
allowLocalhost: true,
oauthProviderConfigs: {
create: (['github', 'spotify', 'google', 'microsoft'] as const).map((id) => ({
id,
id: oauthConfigs[id],
proxiedOAuthConfig: {
create: {
type: id.toUpperCase() as any,
Expand Down Expand Up @@ -90,7 +92,7 @@ async function seed() {
oauthProviderConfig: {
connect: {
projectConfigId_id: {
id,
id: oauthConfigs[id],
projectConfigId: createdProject.configId,
}
}
Expand Down Expand Up @@ -127,7 +129,7 @@ async function seed() {
create: [{
providerAccountId: adminGithubId,
projectConfigId: createdProject.configId,
oauthProviderConfigId: 'github',
oauthProviderConfigId: oauthConfigs.github,
}],
},
},
Expand Down
91 changes: 52 additions & 39 deletions apps/backend/src/app/api/v1/internal/projects/crud.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export const internalProjectsCrudHandlers = createLazyProxy(() => createCrudHand
const ownerPack = ownerPacks.find(p => p.has(user.id));
const userIds = ownerPack ? [...ownerPack] : [user.id];

// TODO: ensure that the oauth configs are valid

const result = await prismaClient.$transaction(async (tx) => {
const project = await tx.project.create({
data: {
Expand All @@ -63,19 +65,19 @@ export const internalProjectsCrudHandlers = createLazyProxy(() => createCrudHand
handlerPath: item.handler_path,
}))
} : undefined,
oauthProviderConfigs: data.config?.oauth_providers ? {
create: data.config.oauth_providers.map(item => ({
oauthProviderConfigs: data.config?.oauth_provider_configs ? {
create: data.config.oauth_provider_configs.map(item => ({
id: item.id,
proxiedOAuthConfig: item.type === "shared" ? {
proxiedOAuthConfig: item.shared ? {
create: {
type: typedToUppercase(ensureSharedProvider(item.id)),
type: typedToUppercase(ensureSharedProvider(item.type)),
}
} : undefined,
standardOAuthConfig: item.type === "standard" ? {
standardOAuthConfig: !item.shared ? {
create: {
type: typedToUppercase(ensureStandardProvider(item.id)),
clientId: item.client_id ?? throwErr('client_id is required'),
clientSecret: item.client_secret ?? throwErr('client_secret is required'),
type: typedToUppercase(ensureStandardProvider(item.type)),
clientId: item.client_id,
clientSecret: item.client_secret,
facebookConfigId: item.facebook_config_id,
microsoftTenantId: item.microsoft_tenant_id,
}
Expand Down Expand Up @@ -118,35 +120,46 @@ export const internalProjectsCrudHandlers = createLazyProxy(() => createCrudHand
},
data: {
authMethodConfigs: {
create: [
...data.config?.oauth_providers ? project.config.oauthProviderConfigs.map(item => ({
enabled: (data.config?.oauth_providers?.find(p => p.id === item.id) ?? throwErr("oauth provider not found")).enabled,
oauthProviderConfig: {
connect: {
projectConfigId_id: {
projectConfigId: project.config.id,
id: item.id,
create: data.config?.auth_method_configs?.map(item => {
switch (item.type) {
case "oauth": {
return {
id: item.id,
enabled: item.enabled,
oauthProviderConfig: {
connect: {
projectConfigId_id: {
id: item.oauth_provider_config_id,
projectConfigId: project.config.id,
}
}
}
}
};
}
})) : [],
...data.config?.magic_link_enabled ? [{
enabled: true,
otpConfig: {
create: {
contactChannelType: 'EMAIL',
}
},
}] : [],
...(data.config?.credential_enabled ?? true) ? [{
enabled: true,
passwordConfig: {
create: {
identifierType: 'EMAIL',
}
},
}] : [],
]
case "password": {
return {
id: item.id,
enabled: item.enabled,
passwordConfig: {
create: {
identifierType: 'EMAIL',
}
}
};
}
case "otp": {
return {
id: item.id,
enabled: item.enabled,
otpConfig: {
create: {
contactChannelType: 'EMAIL',
}
}
};
}
}
}),
}
}
});
Expand All @@ -157,14 +170,14 @@ export const internalProjectsCrudHandlers = createLazyProxy(() => createCrudHand
id: project.config.id,
},
data: {
connectedAccountConfigs: data.config?.oauth_providers ? {
create: project.config.oauthProviderConfigs.map(item => ({
enabled: (data.config?.oauth_providers?.find(p => p.id === item.id) ?? throwErr("oauth provider not found")).enabled,
connectedAccountConfigs: data.config?.connected_account_configs ? {
create: data.config.connected_account_configs.map(item => ({
enabled: item.enabled,
oauthProviderConfig: {
connect: {
projectConfigId_id: {
projectConfigId: project.config.id,
id: item.id,
id: item.oauth_provider_config_id,
}
}
}
Expand Down
Loading
Loading