-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4e5f880
commit 705921e
Showing
9 changed files
with
130 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Dependency directories | ||
node_modules/ | ||
dist | ||
.DS_Store | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# dotenv environment variable files | ||
.env | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
.env.local | ||
|
||
# turbo | ||
.turbo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"editor.defaultFormatter": "biomejs.biome", | ||
"editor.formatOnSave": true, | ||
"editor.formatOnType": true, | ||
"[typescript]": { | ||
"editor.defaultFormatter": "biomejs.biome" | ||
}, | ||
"[typescriptreact]": { | ||
"editor.defaultFormatter": "biomejs.biome" | ||
}, | ||
"[json]": { | ||
"editor.defaultFormatter": "biomejs.biome" | ||
}, | ||
"editor.codeActionsOnSave": { | ||
"quickfix.biome": "explicit", | ||
"source.organizeImports.biome": "explicit" | ||
}, | ||
"[prisma]": { | ||
"editor.defaultFormatter": "Prisma.prisma" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
- [2024-10-02] [gitignore, biome, vscode](https://github.com/RubricLab/auth/commit/017182b92cbae09df53e41423db10c788ba94bf7) | ||
- [2024-10-02] [init](https://github.com/RubricLab/auth/commit/40145b017976d9a7393063a4640e6965af45eac4) | ||
# Changelog | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": ["@rubriclab/config/biome"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export type { | ||
AuthProvider, | ||
AuthProviderConfig, | ||
} from "./lib/types"; | ||
AuthProviderConfig | ||
} from './lib/types' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,49 @@ | ||
import type { PrismaClient } from "@prisma/client"; | ||
import type { PrismaClient } from '@prisma/client' | ||
|
||
export interface UserInfo { | ||
accountId: string; | ||
label: string; | ||
accountId: string | ||
label: string | ||
} | ||
|
||
export interface AuthProviderConfig { | ||
provider: string; | ||
scopes: string[]; | ||
clientId: string; | ||
clientSecret: string; | ||
provider: string | ||
scopes: string[] | ||
clientId: string | ||
clientSecret: string | ||
} | ||
|
||
export interface AuthTokens { | ||
accessToken: string; | ||
refreshToken: string | null; | ||
expiresAt: number | null; | ||
accessToken: string | ||
refreshToken: string | null | ||
expiresAt: number | null | ||
} | ||
|
||
export interface AuthProvider { | ||
config: AuthProviderConfig; | ||
getAuthUrl: ({ userId }: { userId: string }) => string; | ||
getTokensFromCode({ code }: { code: string }): Promise<AuthTokens>; | ||
config: AuthProviderConfig | ||
getAuthUrl: ({ userId }: { userId: string }) => string | ||
getTokensFromCode({ code }: { code: string }): Promise<AuthTokens> | ||
getAccessToken({ | ||
userId, | ||
accountId, | ||
accountId | ||
}: { | ||
userId: string; | ||
accountId: string; | ||
}): Promise<{ accessToken: string }>; | ||
getUserInfo({ token }: { token: string }): Promise<UserInfo>; | ||
userId: string | ||
accountId: string | ||
}): Promise<{ accessToken: string }> | ||
getUserInfo({ token }: { token: string }): Promise<UserInfo> | ||
} | ||
|
||
export type AuthProviders = { | ||
[provider in string]?: AuthProvider; | ||
}; | ||
[provider in string]?: AuthProvider | ||
} | ||
|
||
export interface User { | ||
id: string; | ||
id: string | ||
} | ||
|
||
export interface WebhookInfo { | ||
id: string; | ||
type: string; | ||
enabled: boolean; | ||
id: string | ||
type: string | ||
enabled: boolean | ||
} | ||
|
||
export type DB = PrismaClient; | ||
export type DB = PrismaClient |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,59 @@ | ||
import type { Prisma } from "@prisma/client"; | ||
import type { Prisma } from '@prisma/client' | ||
|
||
import type { AuthProviders } from "./types"; | ||
import type { AuthProviders } from './types' | ||
|
||
export function createAuthActions({ | ||
authProviders, | ||
db, | ||
db | ||
}: { | ||
authProviders: AuthProviders; | ||
authProviders: AuthProviders | ||
db: { | ||
authProvider: Prisma.AuthProviderDelegate; | ||
}; | ||
authProvider: Prisma.AuthProviderDelegate | ||
} | ||
}) { | ||
return { | ||
async getAuthUrl({ | ||
userId, | ||
provider, | ||
provider | ||
}: { | ||
userId: string; | ||
provider: string; | ||
userId: string | ||
provider: string | ||
}) { | ||
const authProvider = authProviders[provider]; | ||
const authProvider = authProviders[provider] | ||
|
||
if (!authProvider) { | ||
throw new Error(`Auth provider not found for ${provider}`); | ||
throw new Error(`Auth provider not found for ${provider}`) | ||
} | ||
|
||
return authProvider.getAuthUrl({ userId }); | ||
return authProvider.getAuthUrl({ userId }) | ||
}, | ||
|
||
async getConnectedAccounts({ userId }: { userId: string }) { | ||
const connectedAccounts = await db.authProvider.findMany({ | ||
where: { userId }, | ||
}); | ||
where: { userId } | ||
}) | ||
|
||
return connectedAccounts; | ||
return connectedAccounts | ||
}, | ||
|
||
async disconnectAuthProvider({ | ||
userId, | ||
provider, | ||
accountId, | ||
accountId | ||
}: { | ||
userId: string; | ||
provider: string; | ||
accountId: string; | ||
userId: string | ||
provider: string | ||
accountId: string | ||
}) { | ||
await db.authProvider.delete({ | ||
where: { | ||
userId_provider_accountId: { | ||
userId, | ||
provider, | ||
accountId, | ||
}, | ||
}, | ||
}); | ||
}, | ||
}; | ||
accountId | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters