Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Security section routing + set first password (#65)
- Loading branch information
Showing
33 changed files
with
997 additions
and
127 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,38 @@ | ||
export type ProviderUserPasswordSet = { | ||
id: string; | ||
name: string; | ||
user: { | ||
id: string; | ||
passwords: { | ||
available: boolean; | ||
}; | ||
}; | ||
}; | ||
|
||
export type SetPasswordErrorRules = { | ||
min_digits: { | ||
error: boolean; | ||
minimum: number; | ||
}; | ||
min_non_digits: { | ||
error: boolean; | ||
minimum: number; | ||
}; | ||
min_total_characters: { | ||
error: boolean; | ||
minimum: number; | ||
}; | ||
}; | ||
|
||
export type SetPasswordError = { | ||
code: string; | ||
locations: [ | ||
{ | ||
column: number; | ||
line: number; | ||
}, | ||
]; | ||
message: string; | ||
path: string[]; | ||
rules: SetPasswordErrorRules; | ||
}; |
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,32 @@ | ||
import type { FetchResult } from "apollo-link"; | ||
import gql from "graphql-tag"; | ||
|
||
import { CreateOrUpdatePasswordInput, User } from "@lib/@types/ProviderUser"; | ||
import { fetchManagement } from "@src/utils/fetchManagement"; | ||
|
||
export type CreateOrUpdatePassword = Promise< | ||
FetchResult<{ | ||
createOrUpdatePassword: User; | ||
}> | ||
>; | ||
|
||
const CREATE_OR_UPDATE_PASSWORD_MUTATION = gql` | ||
mutation createOrUpdatePassword($cleartextPassword: String!, $userId: ID!) { | ||
createOrUpdatePassword( | ||
input: { cleartextPassword: $cleartextPassword, userId: $userId } | ||
) { | ||
id | ||
} | ||
} | ||
`; | ||
|
||
export async function createOrUpdatePassword( | ||
command: CreateOrUpdatePasswordInput, | ||
): CreateOrUpdatePassword { | ||
const operation = { | ||
query: CREATE_OR_UPDATE_PASSWORD_MUTATION, | ||
variables: command, | ||
}; | ||
|
||
return fetchManagement(operation) as CreateOrUpdatePassword; | ||
} |
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,33 @@ | ||
import type { FetchResult } from "apollo-link"; | ||
import gql from "graphql-tag"; | ||
|
||
import type { ProviderUserPasswordSet } from "@lib/@types/Password"; | ||
import { fetchManagement } from "@src/utils/fetchManagement"; | ||
|
||
const IS_USER_PASSWORD_SET_QUERY = gql` | ||
query isUserPasswordSet($userId: String!) { | ||
provider { | ||
id | ||
name | ||
user(filters: { userId: $userId }) { | ||
id | ||
passwords { | ||
available | ||
} | ||
} | ||
} | ||
} | ||
`; | ||
|
||
export async function isUserPasswordSet( | ||
userId: string, | ||
): Promise<FetchResult<{ provider: ProviderUserPasswordSet }>> { | ||
const operation = { | ||
query: IS_USER_PASSWORD_SET_QUERY, | ||
variables: { userId }, | ||
}; | ||
|
||
return fetchManagement(operation) as FetchResult<{ | ||
provider: ProviderUserPasswordSet; | ||
}>; | ||
} |
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,38 @@ | ||
import React from "react"; | ||
|
||
import type { SetPasswordError } from "@lib/@types/Password"; | ||
import type { User } from "@lib/@types/ProviderUser"; | ||
import { HttpVerbs } from "@src/@types/HttpVerbs"; | ||
import { ErrorSettingPassword } from "@src/clientErrors"; | ||
import { fetchJson } from "@src/utils/fetchJson"; | ||
|
||
interface SetPasswordProps { | ||
children: (props: { | ||
setPassword: (passwordInput: string) => Promise<SetPasswordOutput>; | ||
}) => JSX.Element; | ||
} | ||
|
||
export type SetPasswordOutput = { | ||
data: { createOrUpdatePassword: User }; | ||
restrictionRulesError?: SetPasswordError; | ||
}; | ||
|
||
export const SetPassword: React.FC<SetPasswordProps> = ({ children }) => { | ||
async function setPassword( | ||
passwordInput: string, | ||
): Promise<SetPasswordOutput> { | ||
return fetchJson("/api/auth-connect/set-password", HttpVerbs.POST, { | ||
passwordInput, | ||
}).then((response) => { | ||
if (response.status >= 400 && response.status !== 422) { | ||
throw new ErrorSettingPassword(); | ||
} | ||
|
||
return response.json(); | ||
}); | ||
} | ||
|
||
return children({ | ||
setPassword, | ||
}); | ||
}; |
2 changes: 1 addition & 1 deletion
2
src/components/display/fewlines/AccountOverview/AccountOverview.stories.tsx
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
75 changes: 25 additions & 50 deletions
75
src/components/display/fewlines/AccountOverview/AccountOverview.tsx
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,34 @@ | ||
import Link from "next/link"; | ||
import React from "react"; | ||
import styled from "styled-components"; | ||
|
||
import { LoginsIcon } from "../Icons/LoginsIcon/LoginsIcon"; | ||
import { RightChevron } from "../Icons/RightChevron/RightChevron"; | ||
import { NeutralLink } from "../NeutralLink/NeutralLink"; | ||
import { ShadowBox } from "../ShadowBox/ShadowBox"; | ||
import { SecurityIcon } from "../Icons/SecurityIcon/SecurityIcon"; | ||
import { SectionListItem } from "../SectionListItem/SectionListItem"; | ||
|
||
const AccountOverview: React.FC = () => { | ||
export const SECTION_LIST_CONTENT = { | ||
LOGINS: { | ||
text: | ||
"Manage your logins options, including emails, phone numbers and social logins", | ||
icon: <LoginsIcon />, | ||
}, | ||
SECURITY: { | ||
text: | ||
"Set or change your password. You can check your connections history here", | ||
icon: <SecurityIcon />, | ||
}, | ||
}; | ||
|
||
export const AccountOverview: React.FC = () => { | ||
return ( | ||
<> | ||
<ShadowBox> | ||
<Content> | ||
<Link href="/account/logins"> | ||
<NeutralLink> | ||
<Flex> | ||
<LoginsIcon /> | ||
<TextBox> | ||
<Span>LOGINS</Span> | ||
<div> | ||
Manage your logins options, including emails, phone numbers | ||
and social logins | ||
</div> | ||
</TextBox> | ||
<RightChevron /> | ||
</Flex> | ||
</NeutralLink> | ||
</Link> | ||
</Content> | ||
</ShadowBox> | ||
{Object.entries(SECTION_LIST_CONTENT).map(([sectionName, content]) => { | ||
return ( | ||
<SectionListItem | ||
key={sectionName} | ||
sectionName={sectionName} | ||
content={content} | ||
/> | ||
); | ||
})} | ||
</> | ||
); | ||
}; | ||
|
||
export default AccountOverview; | ||
|
||
const Content = styled.div` | ||
cursor: pointer; | ||
`; | ||
|
||
const Flex = styled.div` | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
padding: ${({ theme }) => theme.spaces.xs}; | ||
`; | ||
|
||
export const TextBox = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
max-width: 50%; | ||
font-size: ${({ theme }) => theme.fontSizes.xxs}; | ||
line-height: ${({ theme }) => theme.lineHeights.title}; | ||
`; | ||
|
||
export const Span = styled.p` | ||
font-size: ${({ theme }) => theme.fontSizes.s}; | ||
`; |
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
Oops, something went wrong.
cad3849
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
connect-account-storybook – ./
connect-account-storybook-git-master.fewlines.vercel.app
connect-account-storybook.fewlines.vercel.app
connect-account-storybook.vercel.app
cad3849
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
connect-account – ./
connect-account.vercel.app
connect-account.fewlines.vercel.app
connect-account-git-master.fewlines.vercel.app