-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: use folder with route.ts files fix: migrate back to pages router download/espace-agent/documents/ fix: separate types from routes files fix: use full url for redirect in app/api fix
- Loading branch information
Showing
19 changed files
with
199 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Exception } from '#models/exceptions'; | ||
|
||
export class AgentConnectLogoutFailedException extends Exception { | ||
constructor(args: { cause?: any }) { | ||
super({ | ||
...args, | ||
name: 'LogoutFailedException', | ||
}); | ||
} | ||
} | ||
|
||
export class AgentConnectFailedException extends Exception { | ||
constructor(args: { cause?: any }) { | ||
super({ | ||
name: 'AgentConnectionFailedException', | ||
...args, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import logErrorInSentry from '#utils/sentry'; | ||
import { cleanAgentSession, cleanPathFrom, getPathFrom } from '#utils/session'; | ||
import withSession from '#utils/session/with-session'; | ||
import { redirectTo } from '../../utils'; | ||
import { AgentConnectLogoutFailedException } from '../agent-connect-types'; | ||
|
||
export const GET = withSession(async function logoutCallbackRoute(req) { | ||
try { | ||
const session = req.session; | ||
await cleanAgentSession(session); | ||
const pathFrom = getPathFrom(session); | ||
if (pathFrom) { | ||
await cleanPathFrom(session); | ||
return redirectTo(req, pathFrom); | ||
} else { | ||
return redirectTo(req, '/connexion/au-revoir'); | ||
} | ||
} catch (e: any) { | ||
logErrorInSentry(new AgentConnectLogoutFailedException({ cause: e })); | ||
return redirectTo(req, '/connexion/au-revoir'); | ||
} | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { agentConnectLogoutUrl } from '#clients/authentication/agent-connect/strategy'; | ||
import logErrorInSentry from '#utils/sentry'; | ||
import { setPathFrom } from '#utils/session'; | ||
import withSession from '#utils/session/with-session'; | ||
import { NextResponse } from 'next/server'; | ||
import { redirectTo } from '../../utils'; | ||
import { AgentConnectLogoutFailedException } from '../agent-connect-types'; | ||
|
||
export const GET = withSession(async function logoutRoute(req) { | ||
try { | ||
await setPathFrom(req.session, req.headers.get('referer') || ''); | ||
const url = await agentConnectLogoutUrl(req); | ||
return NextResponse.redirect(url); | ||
} catch (e: any) { | ||
logErrorInSentry(new AgentConnectLogoutFailedException({ cause: e })); | ||
return redirectTo(req, '/connexion/au-revoir'); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Exception } from '#models/exceptions'; | ||
|
||
export class FranceConnectFailedException extends Exception { | ||
constructor(args: { cause?: any }) { | ||
super({ | ||
name: 'FranceConnectFailedException', | ||
...args, | ||
}); | ||
} | ||
} | ||
|
||
export class FranceConnectLogoutFailedException extends Exception { | ||
constructor(args: { cause?: any }) { | ||
super({ | ||
...args, | ||
name: 'LogoutFailedException', | ||
}); | ||
} | ||
} |
10 changes: 6 additions & 4 deletions
10
app/api/auth/france-connect/login.ts → app/api/auth/france-connect/login/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
import { FranceConnectAuthorizeUrl } from '#clients/authentication/france-connect/strategy'; | ||
import { logFatalErrorInSentry } from '#utils/sentry'; | ||
import withSession from '#utils/session/with-session'; | ||
import { FranceConnectFailedException } from './callback'; | ||
import { NextResponse } from 'next/server'; | ||
import { redirectTo } from '../../utils'; | ||
import { FranceConnectFailedException } from '../france-connect-types'; | ||
|
||
export default withSession(async function loginRoute(req, res) { | ||
export const GET = withSession(async function loginRoute(req) { | ||
try { | ||
const url = await FranceConnectAuthorizeUrl(req); | ||
res.redirect(url); | ||
return NextResponse.redirect(url); | ||
} catch (e: any) { | ||
logFatalErrorInSentry(new FranceConnectFailedException({ cause: e })); | ||
res.redirect('/connexion/echec-connexion'); | ||
return redirectTo(req, '/connexion/echec-connexion'); | ||
} | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import logErrorInSentry from '#utils/sentry'; | ||
import { getPathFrom } from '#utils/session'; | ||
import withSession from '#utils/session/with-session'; | ||
import { redirectTo } from '../../utils'; | ||
import { FranceConnectLogoutFailedException } from '../france-connect-types'; | ||
|
||
export const GET = withSession(async function logoutCallbackRoute(req) { | ||
try { | ||
const pathFrom = getPathFrom(req.session); | ||
|
||
req.session.destroy(); | ||
await req.session.save(); | ||
|
||
if (pathFrom) { | ||
return redirectTo(req, pathFrom); | ||
} else { | ||
return redirectTo(req, '/connexion/au-revoir'); | ||
} | ||
} catch (e: any) { | ||
logErrorInSentry(new FranceConnectLogoutFailedException({ cause: e })); | ||
return redirectTo(req, '/connexion/au-revoir'); | ||
} | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { franceConnectLogoutUrl } from '#clients/authentication/france-connect/strategy'; | ||
import logErrorInSentry from '#utils/sentry'; | ||
import { setPathFrom } from '#utils/session'; | ||
import withSession from '#utils/session/with-session'; | ||
import { NextResponse } from 'next/server'; | ||
import { redirectTo } from '../../utils'; | ||
import { FranceConnectLogoutFailedException } from '../france-connect-types'; | ||
|
||
export const GET = withSession(async function logoutRoute(req) { | ||
try { | ||
await setPathFrom( | ||
req.session, | ||
(req.nextUrl.searchParams.get('pathFrom') || '') as string | ||
); | ||
const url = await franceConnectLogoutUrl(req); | ||
return NextResponse.redirect(url); | ||
} catch (e: any) { | ||
logErrorInSentry(new FranceConnectLogoutFailedException({ cause: e })); | ||
return redirectTo(req, '/connexion/au-revoir'); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
|
||
export function redirectTo(req: NextRequest, path: string) { | ||
const requestUrl = new URL(req.url); | ||
const targetUrl = new URL(path, requestUrl.origin); | ||
|
||
return NextResponse.redirect(targetUrl.toString()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.