Fix the URl for google auth
This commit is contained in:
parent
13bfe66c9f
commit
46f7f51d3a
1 changed files with 76 additions and 72 deletions
|
@ -1,3 +1,6 @@
|
||||||
|
import { Capacitor } from '@capacitor/core'
|
||||||
|
import { GoogleAuth } from '@codetrix-studio/capacitor-google-auth'
|
||||||
|
import { Settings } from '@mui/icons-material'
|
||||||
import GoogleIcon from '@mui/icons-material/Google'
|
import GoogleIcon from '@mui/icons-material/Google'
|
||||||
import {
|
import {
|
||||||
Avatar,
|
Avatar,
|
||||||
|
@ -15,15 +18,11 @@ import Cookies from 'js-cookie'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { useNavigate } from 'react-router-dom'
|
import { useNavigate } from 'react-router-dom'
|
||||||
import { LoginSocialGoogle } from 'reactjs-social-login'
|
import { LoginSocialGoogle } from 'reactjs-social-login'
|
||||||
import { API_URL, GOOGLE_CLIENT_ID, REDIRECT_URL } from '../../Config'
|
import { GOOGLE_CLIENT_ID, REDIRECT_URL } from '../../Config'
|
||||||
import { UserContext } from '../../contexts/UserContext'
|
import { UserContext } from '../../contexts/UserContext'
|
||||||
import Logo from '../../Logo'
|
import Logo from '../../Logo'
|
||||||
import { GetUserProfile, login } from '../../utils/Fetcher'
|
import { GetUserProfile, login } from '../../utils/Fetcher'
|
||||||
import { GoogleAuth } from '@codetrix-studio/capacitor-google-auth';
|
import { apiManager } from '../../utils/TokenManager'
|
||||||
import { Capacitor } from '@capacitor/core'
|
|
||||||
import { Settings } from '@mui/icons-material'
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const LoginView = () => {
|
const LoginView = () => {
|
||||||
const { userProfile, setUserProfile } = React.useContext(UserContext)
|
const { userProfile, setUserProfile } = React.useContext(UserContext)
|
||||||
|
@ -34,7 +33,6 @@ const LoginView = () => {
|
||||||
const handleSubmit = async e => {
|
const handleSubmit = async e => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
login(username, password)
|
login(username, password)
|
||||||
|
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
return response.json().then(data => {
|
return response.json().then(data => {
|
||||||
|
@ -63,7 +61,8 @@ const LoginView = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const loggedWithProvider = function (provider, data) {
|
const loggedWithProvider = function (provider, data) {
|
||||||
return fetch(API_URL + `/auth/${provider}/callback`, {
|
const baseURL = apiManager.getApiURL()
|
||||||
|
return fetch(`${baseURL}/auth/${provider}/callback`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
|
@ -151,10 +150,11 @@ const LoginView = () => {
|
||||||
}}
|
}}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
Navigate('/login/settings')
|
Navigate('/login/settings')
|
||||||
|
}}
|
||||||
}
|
>
|
||||||
}
|
{' '}
|
||||||
> <Settings /></IconButton>
|
<Settings />
|
||||||
|
</IconButton>
|
||||||
{/* <img
|
{/* <img
|
||||||
src='/src/assets/logo.svg'
|
src='/src/assets/logo.svg'
|
||||||
alt='logo'
|
alt='logo'
|
||||||
|
@ -335,24 +335,29 @@ const LoginView = () => {
|
||||||
</div>
|
</div>
|
||||||
</Button>
|
</Button>
|
||||||
</LoginSocialGoogle>
|
</LoginSocialGoogle>
|
||||||
</Box> )}
|
</Box>
|
||||||
|
)}
|
||||||
|
|
||||||
{Capacitor.isNativePlatform() && (
|
{Capacitor.isNativePlatform() && (
|
||||||
<Box sx={{ width: '100%' }}>
|
<Box sx={{ width: '100%' }}>
|
||||||
<Button fullWidth variant='soft' size='lg' sx={{ mt: 3, mb: 2 }}
|
<Button
|
||||||
|
fullWidth
|
||||||
|
variant='soft'
|
||||||
|
size='lg'
|
||||||
|
sx={{ mt: 3, mb: 2 }}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
GoogleAuth.initialize({
|
GoogleAuth.initialize({
|
||||||
clientId: import.meta.env.VITE_APP_GOOGLE_CLIENT_ID,
|
clientId: import.meta.env.VITE_APP_GOOGLE_CLIENT_ID,
|
||||||
scopes: ['profile', 'email', 'openid'],
|
scopes: ['profile', 'email', 'openid'],
|
||||||
grantOfflineAccess: true,
|
grantOfflineAccess: true,
|
||||||
});
|
})
|
||||||
GoogleAuth.signIn().then((user) => {
|
GoogleAuth.signIn().then(user => {
|
||||||
console.log("Google user", user);
|
console.log('Google user', user)
|
||||||
|
|
||||||
loggedWithProvider("google", user.authentication)
|
loggedWithProvider('google', user.authentication)
|
||||||
});
|
})
|
||||||
|
}}
|
||||||
}}>
|
>
|
||||||
<div className='flex gap-2'>
|
<div className='flex gap-2'>
|
||||||
<GoogleIcon />
|
<GoogleIcon />
|
||||||
Continue with Google
|
Continue with Google
|
||||||
|
@ -361,7 +366,6 @@ const LoginView = () => {
|
||||||
</Box>
|
</Box>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
Navigate('/signup')
|
Navigate('/signup')
|
||||||
|
|
Loading…
Add table
Reference in a new issue