-
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.
feat(app-signup): add signup logic with firebase connection
- Loading branch information
Showing
11 changed files
with
111 additions
and
11 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
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,4 @@ | ||
import { createAction } from '@reduxjs/toolkit'; | ||
import { SignupInfo } from '../types/signupInfo'; | ||
|
||
export const signup = createAction<SignupInfo>('signup/start'); |
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,34 @@ | ||
import { SignupInfo } from '../types/signupInfo'; | ||
import firebase from 'firebase/app'; | ||
import { FirebaseCollection } from '@pipeline/common'; | ||
import 'firebase/auth'; | ||
import 'firebase/firestore'; | ||
import { User } from '../../_shared/auth/slice'; | ||
|
||
export async function executeSignup(signupInfo: SignupInfo): Promise<User> { | ||
try { | ||
const credentials = await firebase.auth().createUserWithEmailAndPassword(signupInfo.email, signupInfo.password); | ||
if (credentials.user) { | ||
const user = credentials.user; | ||
await firebase.firestore().doc(`${FirebaseCollection.Users}/${user?.uid}`).set({ | ||
email: signupInfo.email, | ||
role: signupInfo.role, | ||
devopsMaturity: signupInfo.devopsMaturity, | ||
}); | ||
return { | ||
id: user.uid, | ||
email: user.email!, | ||
}; | ||
} else { | ||
throw new Error('user-not-created'); | ||
} | ||
} catch (e) { | ||
try { | ||
const currentUser = firebase.auth().currentUser; | ||
if (currentUser !== null) { | ||
await currentUser.delete(); | ||
} | ||
} catch (e) {} | ||
throw e; | ||
} | ||
} |
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,16 @@ | ||
import { useCallback } from 'react'; | ||
import { SignupInfo } from '../types/signupInfo'; | ||
import { useDispatch } from 'react-redux'; | ||
import * as actions from '../actions'; | ||
|
||
export default function useSignup() { | ||
const dispatch = useDispatch(); | ||
|
||
const execute = useCallback((info: SignupInfo) => { | ||
dispatch(actions.signup(info)); | ||
}, []); | ||
|
||
return { | ||
execute, | ||
}; | ||
} |
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 @@ | ||
import signupSaga from './signup'; | ||
|
||
export default signupSaga; |
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,14 @@ | ||
import * as actions from '../actions'; | ||
import { executeSignup } from '../apis/executeSignup'; | ||
import { call, takeEvery, takeLeading } from 'redux-saga/effects'; | ||
import { User } from '../../_shared/auth/slice'; | ||
|
||
function* signupSaga(action: ReturnType<typeof actions.signup>) { | ||
try { | ||
const user: User = yield call(executeSignup, action.payload); | ||
} catch (e) {} | ||
} | ||
|
||
export default function* runSignup() { | ||
yield takeLeading(actions.signup, signupSaga); | ||
} |
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,7 @@ | ||
export interface SignupInfo { | ||
email: string; | ||
password: string; | ||
repeatPassword: string; | ||
role: string; | ||
devopsMaturity: string; | ||
} |
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 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"lib": ["dom", "dom.iterable", "esnext"], | ||
"allowJs": false, | ||
"skipLibCheck": true, | ||
"esModuleInterop": true, | ||
"allowSyntheticDefaultImports": true, | ||
"strict": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"jsx": "preserve", | ||
"outDir": "./build", | ||
"noImplicitAny": true, | ||
"noEmit": false, | ||
"declaration": true | ||
} | ||
} |