# Problema ao redirecionar para o fórum após o login ao usar o MemberMouse

**URL:** <https://meta.discourse.org/t/problem-redirecting-to-forum-after-login-when-using-membermouse/77871>\
**Category:** WordPress\
**Created:** [Janeiro 12, 2018, 7:22pm UTC](https://meta.discourse.org/t/problem-redirecting-to-forum-after-login-when-using-membermouse/77871 "2018-01-12T19:22:17Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![lkramer](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/lkramer/32/83897_2.png) [@lkramer](https://meta.discourse.org/u/lkramer)\
**Post date:** [Maio 29, 2018, 6:52pm UTC](https://meta.discourse.org/t/problem-redirecting-to-forum-after-login-when-using-membermouse/77871/10 "2018-05-29T18:52:58Z")

</div>

Hi Richard. It’s been a while since I worked on this and things seem to be changing from time to time in the discourse plugin (new and better functions keep cropping up) but this is what I did way back them and it still works for us.

We use the wordpress plugin membermouse. And membermouse is written in such a way that after you login, you get redirected to a specific wordpress “welcome member!” page. So this functionality was overriding discourse’s attempt to redirect you back to where you were in discourse.

membermouse has a filter called mm\_login\_redirect where you can change membermouse’s behavior of redirecting the user to that “welcome member!” page. Below is the php code I wrote for that filter.

```
// If the person came from the discourse forum, push them back after logging in
function my_mm_login_redirect( $infoObj ) {

	$current_user = $infoObj->user;
	if ( is_wp_error($current_user) ) return('');
	
	$user_id = $current_user->ID;

	if ( @$_COOKIE['detected_forum_referal'] != '' ) {

		// Payload and signature.
		$payload = @$_COOKIE['mm_cookie_sso'];
		$sig = @$_COOKIE['mm_cookie_sig'];
		
		// Change %0B back to %0A.
		$payload = rawurldecode( str_replace( '%0B', '%0A', rawurlencode( $payload ) ) );
		
		// Validate signature.
		$sso_secret = '###################';
		$sso = new \WPDiscourse\SSO\SSO( $sso_secret );
		if ( ! ( $sso->validate( $payload, $sig ) ) ) {
			return '';
		}
		
		$nonce = $sso->get_nonce( $payload );
		$params = array(
			'nonce' => $nonce,
			'username' => $current_user->user_login,
			'email' => $current_user->user_email,
			'external_id' => $user_id,
		);
		
		$params = apply_filters( 'wpdc_sso_params', $params, $current_user );
		$q = $sso->build_login_string( $params );

		do_action( 'wpdc_sso_provider_before_sso_redirect', $user_id, $current_user );
		
		// Redirect back to Discourse.
		return('https://YOURFORMURLHERE' . '/session/sso_login?' . $q);
	}
	return('');
}
add_filter( 'mm_login_redirect', 'my_mm_login_redirect', 10, 1 );

```

---

_[View the full topic](https://meta.discourse.org/t/problem-redirecting-to-forum-after-login-when-using-membermouse/77871)._
