-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #121 from Macktireh/social-auth
added ability to log in with google
- Loading branch information
Showing
10 changed files
with
6,664 additions
and
32,557 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,36 @@ | ||
import { AnyAction, Dispatch } from "redux"; | ||
|
||
import Axios from "@/config/axios"; | ||
import * as Api from "@/config/apiEndPoint"; | ||
import * as Types from "@/actions/types"; | ||
import loginAction from "./login.action"; | ||
|
||
const googleLoginAction = | ||
(code: any) => | ||
async (dispatch: Dispatch<AnyAction> | any) => { | ||
const config = { | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
}; | ||
|
||
const body = JSON.stringify({ code }); | ||
|
||
console.log("googleLoginAction body", body); | ||
|
||
try { | ||
const res = await Axios.post(Api.googleLoginEndpoint, body, config); | ||
|
||
localStorage.setItem("access", res.data.token.access); | ||
localStorage.setItem("refresh", res.data.token.refresh); | ||
|
||
dispatch(loginAction(true)); | ||
|
||
} catch (error: any) { | ||
dispatch({ | ||
type: Types.LOGIN_FAIL, | ||
}); | ||
} | ||
}; | ||
|
||
export default googleLoginAction; |
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,27 @@ | ||
import ButtonCustom from "@/widgets/ButtonCustom"; | ||
|
||
interface propsTypes { | ||
text: string; | ||
nameClass?: string; | ||
isDisabled?: boolean; | ||
} | ||
|
||
export const GoogleLoginButton: React.FC<propsTypes> = ({ text, nameClass, isDisabled }) => { | ||
const handleReachGoogle = () => { | ||
const GoogleClientID = process.env.REACT_APP_GOOGLE_CLIENT_ID; | ||
const GoogleCallBackURI = process.env.REACT_APP_GOOGLE_CALLBACK_URL; | ||
window.location.replace( | ||
`https://accounts.google.com/o/oauth2/v2/auth?redirect_uri=${GoogleCallBackURI}&prompt=consent&response_type=code&client_id=${GoogleClientID}&scope=openid%20email%20profile&access_type=offline` | ||
); | ||
}; | ||
|
||
return ( | ||
<ButtonCustom | ||
nameClass={nameClass} | ||
pic={"/static/svg/google.svg"} | ||
text={text} | ||
onClick={handleReachGoogle} | ||
isDisabled={isDisabled} | ||
/> | ||
); | ||
}; |
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 |
---|---|---|
|
@@ -78,3 +78,4 @@ self.addEventListener('message', (event) => { | |
}); | ||
|
||
// Any other custom service worker logic can go here. | ||
|
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