Never mind i found the problem, loginWithRedirect takes options object and the targetUrl can be passed there amongst other state properties.
await authClient?.loginWithRedirect({
appState: {
targetUrl: pathname + search
}
});