import NextAuth from 'next-auth'
import Providers from 'next-auth/providers'
export default NextAuth({
providers: [
Providers.Strava({
clientId: process.env.STRAVA_CLIENT_ID,
clientSecret: process.env.STRAVA_CLIENT_SECRET,
authorize: async (credentials) => {
// Exchange authorization code for access token
const response = await fetch('https://www.strava.com/oauth/token', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
client_id: process.env.STRAVA_CLIENT_ID,
client_secret: process.env.STRAVA_CLIENT_SECRET,
code: credentials.authorizationCode,
}),
})
const data = await response.json()
if (!response.ok) {
throw new Error(data.message)
}
return {
accessToken: data.access_token,
refreshToken: data.refresh_token,
expiresIn: data.expires_in,
}
},
}),
],
})
Created
February 20, 2023 08:14
-
-
Save alfianyusufabdullah/3a2611d0db9324029fafa920583055c1 to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment