Salesforce OAUTH accessing profile data #2726
Answered
by
nandhamurali
nandhamurali
asked this question in
Help
-
I have configured Salesforce Provider and am able to successfully log in. Now I am trying to access profile date, but my session object return following user object Can someone help to let me know how I can access the profile data? [...nextauth].js import NextAuth from "next-auth";
import SalesforceProvider from "next-auth/providers/salesforce";
export default NextAuth({
providers: [
SalesforceProvider({
clientId: process.env.SALESFORCE_CLIENT_ID,
clientSecret: process.env.SALESFORCE_CLIENT_SECRET,
profile: (profile, token) => {
return {
id: profile.user_id,
name: profile.name,
email: profile.email,
image: profile.picture,
};
},
}),
],
}); index.js import { signIn, useSession, signOut } from "next-auth/client";
export default function Home() {
const [session, loading] = useSession();
const [data, status] = useSession();
if (session) {
return (
<>
Signed in as {JSON.stringify(session)} <br />
<button onClick={() => signOut()}>Sign out</button>
</>
);
}
return (
<>
Not signed in <br />
<button onClick={() => signIn()}>Sign in</button>
</>
);
} |
Beta Was this translation helpful? Give feedback.
Answered by
nandhamurali
Sep 28, 2021
Replies: 1 comment 1 reply
-
After reading the documentation, writing a custom JWT & Session callback helped. callbacks: {
async jwt(token, user, account, profile, isNewUser) {
if (token && account) {
token.access_token = account.access_token;
}
return token;
},
async session(session, token, user, account, profile) {
session.userid = token.sub;
session.token = token;
return session;
},
}, |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
nandhamurali
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
After reading the documentation, writing a custom JWT & Session callback helped.