-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
40 changed files
with
348 additions
and
672 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
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,39 @@ | ||
import { domain } from './dns' | ||
import { email } from './email' | ||
import { secret } from './secret' | ||
|
||
export const authTable = new sst.aws.Dynamo('LambdaAuthTable', { | ||
fields: { | ||
pk: 'string', | ||
sk: 'string', | ||
}, | ||
ttl: 'expiry', | ||
primaryIndex: { | ||
hashKey: 'pk', | ||
rangeKey: 'sk', | ||
}, | ||
}) | ||
|
||
export const auth = new sst.aws.Auth('Auth', { | ||
forceUpgrade: 'v2', | ||
authorizer: { | ||
handler: 'packages/functions/auth.handler', | ||
link: [ | ||
email, | ||
authTable, | ||
secret.GITHUB_CLIENT_ID, | ||
secret.GITHUB_CLIENT_SECRET, | ||
secret.DATABASE_URL, | ||
], | ||
permissions: [ | ||
{ | ||
actions: ['ses:SendEmail'], | ||
resources: ['*'], | ||
}, | ||
], | ||
}, | ||
domain: { | ||
name: `auth.${domain}`, | ||
dns: sst.cloudflare.dns(), | ||
}, | ||
}) |
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
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
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
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { issuer } from '@openauthjs/openauth' | ||
import { handle } from 'hono/aws-lambda' | ||
import { DynamoStorage } from '@openauthjs/openauth/storage/dynamo' | ||
import { Resource } from 'sst' | ||
import { PasswordProvider } from '@openauthjs/openauth/provider/password' | ||
import { PasswordUI } from '@openauthjs/openauth/ui/password' | ||
import { Email } from '@company/core/src/email/index' | ||
import { User } from '@company/core/src/user/index' | ||
import type { Theme } from '@openauthjs/openauth/ui/theme' | ||
|
||
const theme: Theme = { | ||
title: 'My company', | ||
radius: 'md', | ||
primary: '#1e293b', | ||
favicon: 'https://stack.merlijn.site/favicon.ico', | ||
} | ||
|
||
const app = issuer({ | ||
theme, | ||
storage: DynamoStorage({ | ||
table: Resource.LambdaAuthTable.name, | ||
}), | ||
subjects: User.subjects, | ||
providers: { | ||
password: PasswordProvider( | ||
PasswordUI({ | ||
sendCode: async (email, code) => { | ||
await Email.sendAuth({ email, code }) | ||
}, | ||
}), | ||
), | ||
}, | ||
success: async (ctx, value) => { | ||
if (value.provider === 'password') { | ||
let user = await User.fromEmailWithRole(value.email) | ||
user ??= await User.insert(value.email) | ||
if (!user) throw new Error('Unable to create user') | ||
|
||
return ctx.subject('user', user) | ||
} | ||
throw new Error('Invalid provider') | ||
}, | ||
}) | ||
|
||
export const handler = handle(app) |
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
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,5 @@ | ||
declare module 'lucide-react' { | ||
// Only show type suggestions for Lucide icons with a prefix. | ||
// Otherwise you editor will try to import an icon instead of some component you actually want. | ||
export * from 'lucide-react/dist/lucide-react.prefixed' | ||
} |
Oops, something went wrong.