Skip to content

Commit

Permalink
Fix SocialLogin.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
aelassas committed Dec 30, 2024
1 parent 76674b0 commit bbe20ed
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions frontend/src/components/SocialLogin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { IResolveParams } from '@/types'
import { strings as commonStrings } from '@/lang/common'
import env from '@/config/env.config'
import * as UserService from '@/services/UserService'
import { useUserContext, UserContextType } from '@/context/UserContext'

import FacebookIcon from '@/assets/img/facebook-icon.png'
import AppleIcon from '@/assets/img/apple-icon.png'
Expand Down Expand Up @@ -41,6 +42,8 @@ const SocialLogin = ({
onBlackListed }: SocialLoginProps) => {
const navigate = useNavigate()

const { setUser, setUserLoaded } = useUserContext() as UserContextType

const loginSuccess = async (socialSignInType: bookcarsTypes.SocialSignInType, accessToken: string, email: string, fullName: string, avatar?: string) => {
const data: bookcarsTypes.SignInPayload = {
socialSignInType,
Expand All @@ -58,10 +61,16 @@ const SocialLogin = ({
if (onBlackListed) {
onBlackListed()
}
} else if (redirectToHomepage) {
navigate('/')
} else {
navigate(0)
const user = await UserService.getUser(res.data._id)
setUser(user)
setUserLoaded(true)

if (redirectToHomepage) {
navigate('/')
} else {
navigate(0)
}
}
} else if (onSignInError) {
onSignInError()
Expand Down

0 comments on commit bbe20ed

Please sign in to comment.