-
Notifications
You must be signed in to change notification settings - Fork 2
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
7 changed files
with
109 additions
and
20 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,26 @@ | ||
import { CognitoIdentityProviderClient } from '@aws-sdk/client-cognito-identity-provider'; | ||
import type { DefaultConfigs } from 'common/types/api'; | ||
import { atom, useAtom, useAtomValue } from 'jotai'; | ||
import { NEXT_PUBLIC_API_ORIGIN } from 'utils/envValues'; | ||
|
||
const defaultsAtom = atom<DefaultConfigs | { [Key in keyof DefaultConfigs]?: undefined }>({}); | ||
const clientAtom = atom((get) => { | ||
const defaults = get(defaultsAtom); | ||
|
||
return new CognitoIdentityProviderClient( | ||
defaults.accessKey | ||
? { | ||
endpoint: NEXT_PUBLIC_API_ORIGIN, | ||
region: defaults.region, | ||
credentials: { accessKeyId: defaults.accessKey, secretAccessKey: defaults.secretKey }, | ||
} | ||
: {}, | ||
); | ||
}); | ||
|
||
export const useCognitoClient = () => { | ||
const [defaults, setDefaults] = useAtom(defaultsAtom); | ||
const cognitoClient = useAtomValue(clientAtom); | ||
|
||
return { defaults, setDefaults, cognitoClient }; | ||
}; |
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 |
---|---|---|
|
@@ -15,7 +15,6 @@ | |
height: 100%; | ||
padding: 0 16px; | ||
margin: 0 auto; | ||
user-select: none; | ||
} | ||
|
||
.userBtn { | ||
|
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 |
---|---|---|
@@ -1,11 +1,21 @@ | ||
import { DEFAULT_USER_POOL_CLIENT_ID, DEFAULT_USER_POOL_ID } from 'service/envValues'; | ||
import { returnSuccess } from 'service/returnStatus'; | ||
import { | ||
ACCESS_KEY, | ||
DEFAULT_USER_POOL_CLIENT_ID, | ||
DEFAULT_USER_POOL_ID, | ||
REGION, | ||
SECRET_KEY, | ||
} from 'service/envValues'; | ||
import { defineController } from './$relay'; | ||
|
||
export default defineController(() => ({ | ||
get: () => | ||
returnSuccess({ | ||
get: () => ({ | ||
status: 200, | ||
body: { | ||
userPoolId: DEFAULT_USER_POOL_ID, | ||
userPoolClientId: DEFAULT_USER_POOL_CLIENT_ID, | ||
}), | ||
region: REGION, | ||
accessKey: ACCESS_KEY, | ||
secretKey: SECRET_KEY, | ||
}, | ||
}), | ||
})); |
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,8 +1,6 @@ | ||
import type { DefineMethods } from 'aspida'; | ||
import type { EntityId } from 'common/types/brandedId'; | ||
import type { DefaultConfigs } from 'common/types/api'; | ||
|
||
export type Methods = DefineMethods<{ | ||
get: { | ||
resBody: { userPoolId: EntityId['userPool']; userPoolClientId: EntityId['userPoolClient'] }; | ||
}; | ||
get: { resBody: DefaultConfigs }; | ||
}>; |
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,9 @@ | ||
import type { EntityId } from './brandedId'; | ||
|
||
export type DefaultConfigs = { | ||
userPoolId: EntityId['userPool']; | ||
userPoolClientId: EntityId['userPoolClient']; | ||
region: string; | ||
accessKey: string; | ||
secretKey: string; | ||
}; |