Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
ttizze committed Jul 14, 2024
1 parent fe74f29 commit cc25874
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 9 additions & 4 deletions web/app/routes/api.auth.callback.google.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ import type { LoaderFunctionArgs } from '@remix-run/node'
import { authenticator } from '../utils/auth.server'

export const loader = ({ request }: LoaderFunctionArgs) => {
return authenticator.authenticate('google', request, {
successRedirect: '/',
failureRedirect: '/auth/login',
})
try {
return authenticator.authenticate('google', request, {
successRedirect: '/',
failureRedirect: '/auth/login',
})
} catch (error) {
console.error('Google authentication error:', error)
return new Response('Authentication failed', { status: 500 })
}
}
4 changes: 0 additions & 4 deletions web/app/utils/auth.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,17 @@ const googleStrategy = new GoogleStrategy<User>(
const user = await prisma.user.findUnique({
where: { email: profile.emails[0].value },
})

if (user) {
return user
}

const newUser = await prisma.user.create({
data: {
id: Number(profile.id),
email: profile.emails[0].value || '',
password: '',
name: profile.displayName,
provider: 'google',
},
})

return newUser
},
)
Expand Down

0 comments on commit cc25874

Please sign in to comment.