import GithubProvider from "next-auth/providers/github"
import GoogleProvider from "next-auth/providers/google"
const GITHUB_ID: string = process.env.GITHUB_ID as string;
const GITHUB_SECRET: string = process.env.GITHUB_SECRET as string;
const GOOLE_ID: string = process.env.GOOGLE_ID as string;
const GOOGLE_SECRET: string = process.env.GOOGLE_SECRET as string;
if (typeof GITHUB_ID !== "string") {
throw new Error("GITHUB_ID is not a String! check your env file")
}
if (typeof GITHUB_SECRET !== "string") {
throw new Error("GITHUB_SECRET is not a String, check your env file")
}
if (typeof GOOLE_ID !== "string") {
throw new Error("GOOLE_ID is not a String, check your env file")
}
if (typeof GOOGLE_SECRET !== "string") {
throw new Error("GITHUB_ID is not a String, check your env file")
}
export const options = {
providers: [
GithubProvider({
profile(profile) {
console.log("Profile Github", profile)
return {
...profile,
id: profile.sub,
}
},
clientId: GITHUB_ID,
clientSecret: GITHUB_SECRET
}),
GoogleProvider({
profile(profile) {
console.log("Profile Google", profile)
return {
...profile,
id: profile.sub,
}
},
clientId: GOOLE_ID,
clientSecret: GOOGLE_SECRET,
})
]
}
I am currently facing an issue with declaring environment variables as strings in the clientID
and clientSecret
. Initially, I encountered a type error where process.env.GITHUB_ID
was showing as 'string | undefined' and could not be assigned to clientID
which requires a 'string' type. I am open to suggestions for a better approach to handling this issue.
I have attempted converting process.env.GITHUB_ID
to a string using other methods, but none seem to resolve the problem effectively.