feat: enhance authentication flow by redirecting unauthenticated users and updating token scope
This commit is contained in:
parent
fce459679c
commit
b467ae704c
@ -1,6 +1,8 @@
|
||||
import { authOptions } from "@/authOptions";
|
||||
import axios from "axios";
|
||||
import moment, { Moment } from "moment";
|
||||
import { getSession } from "next-auth/react";
|
||||
import { redirect } from "next/navigation";
|
||||
|
||||
moment.locale("fr");
|
||||
|
||||
@ -35,7 +37,7 @@ axiosInstance.interceptors.request.use(async (config) => {
|
||||
try {
|
||||
const session = await getSession();
|
||||
if (!session) {
|
||||
throw new Error("User is not authenticated");
|
||||
redirect(authOptions.pages!.signIn!);
|
||||
}
|
||||
|
||||
cachedAccessToken = session.accessToken;
|
||||
|
@ -18,7 +18,7 @@ export const authOptions: AuthOptions = {
|
||||
authorization: {
|
||||
url: process.env.OAUTH_AUTHORIZATION_URL,
|
||||
params: {
|
||||
scope: "openid email profile offline_access",
|
||||
scope: "openid email profile",
|
||||
response_type: "code",
|
||||
},
|
||||
},
|
||||
@ -28,6 +28,7 @@ export const authOptions: AuthOptions = {
|
||||
userinfo: process.env.OAUTH_USERINFO_URL,
|
||||
issuer: process.env.OAUTH_ISSUER,
|
||||
jwks_endpoint: process.env.OAUTH_JWKS_ENDPOINT,
|
||||
wellKnown: `${process.env.OAUTH_ISSUER}/.well-known/openid-configuration`,
|
||||
profile(profile: Session["user"]) {
|
||||
return {
|
||||
id: profile.sub || profile.id,
|
||||
|
Loading…
Reference in New Issue
Block a user