Skip to content

Commit cc42821

Browse files
committed
feat: enhance authentication response with user base URL
- Added the user's base URL to the authentication response, allowing for better handling of redirect URIs. - Implemented a method in the login component to normalize the redirect URI, ensuring proper formatting and fallback handling.
1 parent 1ad48c0 commit cc42821

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

apps/api/src/core/auth/auth.controller.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ export class AuthController extends AbstractController {
3636
@ApiOperation({ summary: 'Authentification interne utilisateur' })
3737
public async authenticateWithLocal(@Res() res: Response, @ReqIdentity() user: AgentType): Promise<Response> {
3838
const tokens = await this.service.createTokens(user);
39+
const uri = typeof user?.baseURL === 'string' && user.baseURL.trim().length > 0 ? user.baseURL.trim() : '/'
3940
return res.status(HttpStatus.OK).json({
4041
...tokens,
42+
uri,
4143
user,
4244
});
4345
}

apps/web/src/pages/login.vue

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,25 @@ export default defineNuxtComponent({
6666
}
6767
},
6868
methods: {
69+
normalizeRedirectUri(uri?: string): string {
70+
const fallback = '/'
71+
if (typeof uri !== 'string') return fallback
72+
const value = uri.trim()
73+
if (!value) return fallback
74+
if (!value.startsWith('/')) return `/${value}`
75+
return value
76+
},
6977
async submit() {
7078
this.pending = true
7179
try {
72-
await useAuth().loginWith('local', {
80+
const auth = useAuth()
81+
const response: any = await auth.loginWith('local', {
7382
body: this.formData,
7483
})
84+
await auth.fetchUser()
85+
const authUser = (auth as any)?.user?.value || (auth as any)?.user
86+
const uri = this.normalizeRedirectUri(authUser?.baseURL || response?.data?.uri)
87+
await this.$router.push(uri)
7588
} catch (error) {
7689
this.$q.notify({
7790
type: 'negative',

0 commit comments

Comments
 (0)