Changeset 13f1472 for frontend/src/Auth
- Timestamp:
- 09/18/22 18:09:53 (2 years ago)
- Branches:
- master
- Parents:
- 49b0bbd
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
frontend/src/Auth/auth.js
r49b0bbd r13f1472 6 6 import '../App.css' 7 7 import env from "../env"; 8 import { GoogleLogin } from 'react-google-login'; 9 import FacebookLogin from 'react-facebook-login'; 8 10 9 11 const setAuthCookie = (token) => { … … 29 31 }); 30 32 setLoading(false) 33 }) 34 } 35 36 const googleLoginResponse = (response)=>{ 37 console.log(response) 38 setLoading(true) 39 console.log(response.tokenId) 40 setAuthCookie('Bearer '+response.tokenId) 41 axios.post(env.api+'Users/register',{email: response.profileObj.email, password:'', isConfirmed: true}).then(res => { 42 setUser(res.data) 43 setLoading(false) 44 history(res.data.isAdmin ? '/dashboard' : '/') 45 }) 46 } 47 48 const facebookLoginResponse = (response) =>{ 49 console.log(response) 50 setLoading(true) 51 setAuthCookie('Bearer '+response.accessToken) 52 axios.post(env.api+'Users/register',{email: response.email, password:'', isConfirmed: true}).then(res => { 53 setUser(res.data) 54 setLoading(false) 55 history(res.data.isAdmin ? '/dashboard' : '/') 31 56 }) 32 57 } … … 73 98 74 99 <Form.Item style={{margin:'0px'}}> 75 <Button type="primary" htmlType="submit" className="login-form-button" loading={loading} >100 <Button type="primary" htmlType="submit" className="login-form-button" loading={loading} style={{marginBottom:'5px'}}> 76 101 Log in 77 102 </Button> 103 <br/> 104 <GoogleLogin 105 clientId="748923557453-ljii8ulhti93man769d2dd9soi7038j5.apps.googleusercontent.com" 106 buttonText="Логирај се со Google" 107 onSuccess={googleLoginResponse} 108 /> 109 <FacebookLogin 110 appId="1455131645009417" 111 size={'small'} 112 textButton={'Логирај се со FB'} 113 icon="fa-facebook" 114 fields="name,email" 115 callback={facebookLoginResponse} /> 78 116 <div> 79 117 Или <a href={"/register"}>регистрирај се!</a> … … 102 140 } 103 141 setLoading(true) 104 axios.post(env.api+'Users/register',{email: attr.email, password: attr.password }).then(res => {142 axios.post(env.api+'Users/register',{email: attr.email, password: attr.password,isConfirmed:false}).then(res => { 105 143 setAuthCookie(res.data.token) 106 144 setUser(res.data) … … 109 147 }) 110 148 } 149 150 const googleLoginResponse = (response)=>{ 151 console.log(response) 152 setLoading(true) 153 console.log(response.tokenId) 154 setAuthCookie('Bearer '+response.tokenId) 155 axios.post(env.api+'Users/register',{email: response.profileObj.email, password:'', isConfirmed: true}).then(res => { 156 setUser(res.data) 157 setLoading(false) 158 history('/') 159 }) 160 } 161 162 const facebookLoginResponse = (response) =>{ 163 console.log(response) 164 setLoading(true) 165 setAuthCookie('Bearer '+response.accessToken) 166 axios.post(env.api+'Users/register',{email: response.email, password:'', isConfirmed: true}).then(res => { 167 setUser(res.data) 168 setLoading(false) 169 history('/') 170 }) 171 } 172 173 111 174 return( 112 175 <div style={{width:'100vw',height:'100vh', textAlign:'center', backgroundColor:'#F2F2F2'}}> … … 165 228 166 229 <Form.Item style={{margin:'0px'}}> 167 <Button type="primary" htmlType="submit" className="login-form-button" loading={loading} >230 <Button type="primary" htmlType="submit" className="login-form-button" loading={loading} style={{marginBottom:'5px'}}> 168 231 Register 169 232 </Button> 233 <br/> 234 <GoogleLogin 235 clientId="748923557453-ljii8ulhti93man769d2dd9soi7038j5.apps.googleusercontent.com" 236 buttonText="Регистрирај се со Google" 237 onSuccess={googleLoginResponse} 238 /> 239 <div style={{margin:'5px'}}/> 240 <FacebookLogin 241 appId="1455131645009417" 242 size={'small'} 243 textButton={'Регистрирај се со FB'} 244 icon="fa-facebook" 245 fields="name,email" 246 callback={facebookLoginResponse} /> 170 247 <div> 171 248 Или <a href={"/login"}>најави се!</a>
Note:
See TracChangeset
for help on using the changeset viewer.