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

Email confirmation flow #522

Open
wants to merge 37 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
b65595d
setup create course page
ZheleznovTN Apr 12, 2022
e40db72
implement content builder component
ZheleznovTN Apr 12, 2022
6e4760e
implement currency input component
ZheleznovTN Apr 12, 2022
793ae5e
fix breakpoints
ZheleznovTN Apr 14, 2022
53bed13
implement switch component
ZheleznovTN Apr 15, 2022
0c6ff31
implement switch formik field
ZheleznovTN Apr 18, 2022
99e51c4
setup redux store for courses
ZheleznovTN Apr 19, 2022
03dfa0d
setup course page
ZheleznovTN Apr 19, 2022
c19d3de
implement responsive component, implement course main info
ZheleznovTN Apr 19, 2022
aba5b53
setup content list component
ZheleznovTN Apr 19, 2022
b997fb0
implement members component
ZheleznovTN Apr 20, 2022
cc8f4ab
implement two columns grid component
ZheleznovTN Apr 20, 2022
34c4806
lessons, reviews, members, materials setup and empty states
ZheleznovTN Apr 20, 2022
0fda365
implement materials block
ZheleznovTN Apr 22, 2022
1c715bc
materials side modal
ZheleznovTN Apr 22, 2022
ae1e33c
implement action modal, refactoring
ZheleznovTN Apr 23, 2022
1ff3a3c
implement materials block
ZheleznovTN Apr 25, 2022
50b2ca6
implement reviews content block
ZheleznovTN Apr 25, 2022
a1270c0
implement all reviews side modal
ZheleznovTN Apr 25, 2022
382b35a
implement add review side modal
ZheleznovTN Apr 25, 2022
e47d670
Merge branch 'dev' into course-page
ZheleznovTN Apr 28, 2022
73a5a63
implement course progress bar component
ZheleznovTN Apr 29, 2022
4128ab8
implement course lesson item component
ZheleznovTN Apr 29, 2022
9512acd
implement progress list component and progress list component
ZheleznovTN May 1, 2022
85a5b2c
add more button to course main info container
ZheleznovTN May 1, 2022
e405787
implement course and lessons more options
ZheleznovTN May 1, 2022
eff4565
minor changes
ZheleznovTN May 3, 2022
d7fb377
implement members page
ZheleznovTN May 4, 2022
2c5ba00
Merge branch 'dev' into members-page
ZheleznovTN May 5, 2022
f838b03
implement confirmation email page
ZheleznovTN May 5, 2022
5ef8678
refactoring
ZheleznovTN May 5, 2022
f22f850
fixes to detect users for sign up confirmation
neil-sweetcodepro May 6, 2022
2bd6e57
implement non confirmed flow
ZheleznovTN May 9, 2022
3f3d8b2
implement loader provider
ZheleznovTN May 9, 2022
da47c95
fix login
ZheleznovTN May 10, 2022
0b00181
minor fix
ZheleznovTN May 12, 2022
6fbb7f3
Merge branch 'dev' into email-confirmation-flow
lmmrssa May 17, 2022
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
9 changes: 6 additions & 3 deletions api/src/controllers/userController.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,18 @@ const registerUser = async (req, res) => {
})
}

const responseData = {}

if (isCognito) {
await registerCognito(username, password)
responseData.message = 'Code for sign up confirmation was sent to your email'
responseData.forSignUpConfirmation = true
} else {
await registerLocal(username, password)
responseData.message = 'The user has been registered'
}

res.status(201).send({
message: 'The user has been registered'
})
res.status(201).send(responseData)
} catch (err) {
res.status(409).json({ error: err.message })
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^11.1.0",
"@testing-library/user-event": "^12.1.10",
"aws-amplify": "^3.3.27",
"aws-amplify": "^4.3.21",
"axios": "^0.21.1",
"classnames": "^2.3.1",
"dayjs": "^1.10.7",
Expand Down
1 change: 1 addition & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="app"></div>
<div id="app-portal-container"></div>
<div id="app-loader-container"></div>
<script type="text/jsx" src="index.jsx"></script>
</body>
</html>
27 changes: 19 additions & 8 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@ import { QueryClientProvider } from "react-query";
import customParseFormat from "dayjs/plugin/customParseFormat";
import { Switch, BrowserRouter as Router, Route } from "react-router-dom";

import { SignInPage } from "screens/auth/sign-in";
import { SignUpPage } from "screens/auth/sign-up";
import { ForgotPasswordPage } from "screens/auth/forgot-password";
import { AdditionalInfoPage } from "screens/auth/additional-info";
import {
SignInPage,
SignUpPage,
ConfirmEmailPage,
ForgotPasswordPage,
AdditionalInfoPage,
} from "screens/auth";

import { PrivateRoute } from "components/privateRoute";
import { SideBarNavigation } from "common/side-bar-navigation";

import { Routes } from "routes";
import ScrollToTop from "utils/scrollToTop";
import { Routes as PathRoutes } from "constants/routes";
import { SearchBarProvider } from "providers/search-bar";

import { queryClient } from "./reactQuery";
Expand Down Expand Up @@ -43,14 +47,21 @@ function App() {
<Router>
<ScrollToTop>
<Switch>
<Route component={SignInPage} path="/login" />
<Route component={SignUpPage} path="/register" />
<Route component={ForgotPasswordPage} path="/forgot-password" />
<Route component={SignInPage} path={PathRoutes.Auth.Login} />
<Route component={SignUpPage} path={PathRoutes.Auth.Register} />
<Route
component={ConfirmEmailPage}
path={PathRoutes.Auth.ConfirmEmail}
/>
<Route
component={ForgotPasswordPage}
path={PathRoutes.Auth.ForgotPassword}
/>

<PrivateRoute
exact
path="/additional-info"
component={AdditionalInfoPage}
path={PathRoutes.Auth.AdditionalInfo}
/>

<Route component={MainApp} />
Expand Down
113 changes: 1 addition & 112 deletions src/actions/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,14 @@ import Amplify, { Auth } from "aws-amplify";

import { api } from "api";
import { authConfig } from "config/amplify";
import { getErrorMessage } from "utils/error";
import { setCurrentUser } from "store/user/slices";
import {
USER_LOGOUT,
USER_LOGIN_FAIL,
USER_LOGIN_SUCCESS,
ACCESS_TOKEN_SUCCESS,
} from "constants/userConstants";

// import { news } from "./community";
// import { visitCommunity } from "./communityActions";
import { USER_LOGOUT } from "constants/userConstants";

const isCognito = process.env.REACT_APP_AUTH_METHOD === "cognito";

if (isCognito) {
Amplify.configure({ Auth: { ...authConfig } });
}

// TODO: Move to store/thunk when reduxjs/toolkit will be setuped
const makeLogout = (dispatch) => {
// dispatch({ type: USER_DETAILS_FAIL, payload: message });
localStorage.clear();
Expand All @@ -39,106 +28,6 @@ export const logout = () => async (dispatch) => {
}
};

// TODO: Move to store/thunk when reduxjs/toolkit will be setuped
export const getAccessToken = () => async (dispatch) => {
try {
const response = await api.auth.getToken();

if (response.status !== 201) {
makeLogout(dispatch);
return Promise.reject();
}

dispatch({ type: ACCESS_TOKEN_SUCCESS, payload: true });
return Promise.resolve();
} catch (error) {
makeLogout(dispatch);
return Promise.reject(error);
}
};

// TODO: Move to store/thunk when reduxjs/toolkit will be setuped
export const login =
({ name, password }) =>
async (dispatch) => {
try {
let authData = {};
let response;
if (isCognito) {
response = await Auth.signIn(name, password);
const id = response?.attributes?.sub || "";
authData = {
id,
token: response?.signInUserSession?.idToken?.jwtToken || "",
};
await api.auth.login({ id });
} else {
response = await api.auth.login({ username: name, password });
authData = response.data;
}

localStorage.setItem("userInfo", JSON.stringify(authData));

const profile = await api.user.get({ id: authData.id });
dispatch(setCurrentUser({ ...response, ...profile?.data?.results }));

// await getAccessToken()(dispatch); // access token is already received in login response
// const community = await news()(dispatch);
// await visitCommunity(community.id)(dispatch);

dispatch({ type: USER_LOGIN_SUCCESS, payload: response });
return Promise.resolve(response);
} catch (error) {
dispatch({ type: USER_LOGIN_FAIL, payload: getErrorMessage(error) });
return Promise.reject(error);
}
};

export const register =
({ name, password }) =>
async (dispatch) => {
try {
await api.auth.register({ username: name, password });

// no auto login for cognito since it needs to confirm email with a code
if (!isCognito) {
await login({ name, password })(dispatch);
}

return Promise.resolve();
} catch (error) {
return Promise.reject(error);
}
};

// TODO: Why there is no functionality to request code without cognito?
export const requestCode = async (username) => {
try {
let response;
if (isCognito) {
const data = await api.auth.forgotPassword(username);
response =
data.data.details.CodeDeliveryDetails.AttributeName.split("_").join(
" "
);
}
return Promise.resolve(response);
} catch (error) {
return Promise.reject(error);
}
};

export const resetPassword = async ({ username, code, password }) => {
try {
if (isCognito) {
await api.auth.forgotPasswordSubmit(username, code, password);
}
return Promise.resolve();
} catch (error) {
return Promise.reject(error);
}
};

export const changePassword = async ({ oldPassword, newPassword }) => {
try {
if (isCognito) {
Expand Down
7 changes: 5 additions & 2 deletions src/api/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ export const forgotPasswordSubmit = ({ username, code, newPassword }) =>
newPassword,
});

export const confirmSignup = ({ username, code }) =>
export const confirmEmail = ({ email, code }) =>
apiInstance.post("/users/confirm-sign-up", {
username,
code,
username: email,
});

export const resendEmailCode = ({ email }) =>
apiInstance.post("/users/resend-sign-up-code", { username: email });
Loading