A
A
Albert Ushakov2021-03-20 13:33:37
WordPress
Albert Ushakov, 2021-03-20 13:33:37

How to implement a WP based backend for authorization and using wp functions in a React native app?

The first thing that comes to mind, and the simplest, is to file the API on the WP side and simply authorize it on each request. But these are unnecessary actions and there is no protection on the client side. Plus, it's not clear how cookies work.

function user_auth($user_id){

  $user = get_user_by( 'id', $user_id ); 
  if( $user ) {
    wp_set_auth_cookie( $user_id, true );
    wp_set_current_user( $user_id, $user->user_login );
  }
}


The second is to authorize through a token, but this will lead to logging out of all devices if you log out of your account anywhere.

The third is client-side authorization. Store data on the client (Without client data, of course) only ID. Forcibly change the global authorization variable on the WP side with each request.

Maybe you have a solution or a different view for a similar task? I'm waiting for your answers.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anatoly Kulikov, 2021-03-20
@anatoly_kulikov

Here is part of the answer: https ://anatolykulikov.ru/article/multilingual-plu...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question