feature/auth #2
@ -33,7 +33,7 @@ const Auth = () => {
|
|||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div>
|
<div>
|
||||||
<p>Welcome, {session.user?.name || "User"}!</p>
|
<p>Welcome, {session.user.name || "User"}!</p>
|
||||||
<button
|
<button
|
||||||
style={{
|
style={{
|
||||||
padding: "10px 20px",
|
padding: "10px 20px",
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { AuthOptions } from "next-auth";
|
import { AuthOptions, Session } from "next-auth";
|
||||||
|
|
||||||
|
|
||||||
export const authOptions: AuthOptions = {
|
export const authOptions: AuthOptions = {
|
||||||
providers: [
|
providers: [
|
||||||
@ -8,6 +9,7 @@ export const authOptions: AuthOptions = {
|
|||||||
type: "oauth",
|
type: "oauth",
|
||||||
clientId: process.env.OAUTH_CLIENT_ID,
|
clientId: process.env.OAUTH_CLIENT_ID,
|
||||||
clientSecret: process.env.OAUTH_CLIENT_SECRET,
|
clientSecret: process.env.OAUTH_CLIENT_SECRET,
|
||||||
|
wellKnown: process.env.OAUTH_WELL_KNOWN,
|
||||||
authorization: {
|
authorization: {
|
||||||
url: process.env.OAUTH_AUTHORIZATION_URL,
|
url: process.env.OAUTH_AUTHORIZATION_URL,
|
||||||
params: {
|
params: {
|
||||||
@ -15,25 +17,22 @@ export const authOptions: AuthOptions = {
|
|||||||
response_type: "code",
|
response_type: "code",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
checks: ["pkce", "state"],
|
||||||
|
idToken: true,
|
||||||
token: process.env.OAUTH_TOKEN_URL,
|
token: process.env.OAUTH_TOKEN_URL,
|
||||||
userinfo: process.env.OAUTH_USERINFO_URL,
|
userinfo: process.env.OAUTH_USERINFO_URL,
|
||||||
issuer: process.env.OAUTH_ISSUER,
|
issuer: process.env.OAUTH_ISSUER,
|
||||||
jwks_endpoint: process.env.OAUTH_JWKS_ENDPOINT,
|
jwks_endpoint: process.env.OAUTH_JWKS_ENDPOINT,
|
||||||
profile(profile) {
|
profile(profile: Session["user"]) {
|
||||||
return {
|
return {
|
||||||
id: profile.sub || profile.id,
|
id: profile.sub || profile.id,
|
||||||
name:
|
name:
|
||||||
profile.name ||
|
profile.name || profile.preferred_username ||
|
||||||
`${profile.given_name} ${profile.family_name}`,
|
`${profile.given_name} ${profile.family_name}`
|
||||||
email: profile.email,
|
|
||||||
image: profile.picture || null,
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
session: {
|
|
||||||
strategy: "jwt",
|
|
||||||
},
|
|
||||||
callbacks: {
|
callbacks: {
|
||||||
async jwt({ token, account, user }) {
|
async jwt({ token, account, user }) {
|
||||||
if (account) {
|
if (account) {
|
||||||
|
7
src/types/next-auth.d.ts
vendored
7
src/types/next-auth.d.ts
vendored
@ -9,7 +9,12 @@ declare module "next-auth" {
|
|||||||
expiresAt: number;
|
expiresAt: number;
|
||||||
user: {
|
user: {
|
||||||
id: string;
|
id: string;
|
||||||
} & DefaultSession["user"];
|
sub: string;
|
||||||
|
name: string;
|
||||||
|
preferred_username: string;
|
||||||
|
given_name: string;
|
||||||
|
family_name: string;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Account {
|
interface Account {
|
||||||
|
Loading…
Reference in New Issue
Block a user