Dropsolid Drupal 10 Upkeep and Help Service 8 and React Native

21 Jun 8 and React Native Niels A 8 Tech In the future you may get up with Drupal Development Company subsequent massive thought that can shake Drupal Development Company world in Drupal Development Company most ungentle manner. You resolve to construct an app, since you’ll have full entry to all options of Drupal Development Company machine that you really want your resolution to work on. However then it dawns on you Drupal 10 Upkeep and Help Service you’ll truly must construct a number of apps in fully totally different languages whereas discovering a manner for them to serve Drupal Development Company identical content material… You then begin to realise that you just gained’t have the ability to step into Drupal Development Company sneakers of Drupal Development Company greats, as a result of net know-how is holding you again. Happily,  8 and React Native are right here to avoid wasting your day – and your dream! On this weblog submit you may learn how one can leverage 8 to function Drupal Development Company back-end to your React Native app.  First, nevertheless, a fast definition of what these applied sciences are Drupal 10 Upkeep and Help Service is an open supply content material administration system based mostly on PHP. React Native is a framework to construct native apps utilizing JavaScript and React. If you wish to learn extra about 8 or React Native, you are invited to examine Drupal Development Company sources at Drupal Development Company backside of this text.   Why React Native? There are a myriad of front-end applied sciences out there to you today. Drupal Development hottest ones are Angular and React. Each applied sciences let you construct apps, however there’s a massive distinction in how Drupal Development Company apps shall be constructed. Drupal Development benefit of using React Native is that it allows you to construct an app utilizing JavaScript, whereas changing Drupal Development Company JavaScript into native code. In distinction, Angular or Ionic let you create a hybrid app, which principally is an internet site that will get embedded in an internet view. Though Drupal Development Company profit right here is that you just’re capable of entry Drupal Development Company native options of a tool. On this case, we desire React Native, as a result of we need to construct iOS and Android Drupal 10 functions that run natively.   Headless Considered one of Drupal Development Company massive buzzwords that is been doing Drupal Development Company rounds in Drupal Development Company neighborhood currently is ‘Headless’. A headless is definitely a utility the place Drupal Development Company front-end just isn’t served by , however by a unique know-how. You continue to get Drupal Development Company advantages of a prime notch and very versatile content material administration system, however you additionally get Drupal Development Company advantages of your chosen front-end know-how. On this instance, you may uncover the way to arrange a local iOS and Android utility that will get its knowledge from a web site. To entry Drupal Development Company info, customers should log in to Drupal Development Company app, which permits Drupal Development Company app to serve content material tailor-made to Drupal Development Company preferences of Drupal Development Company consumer. Essential in Drupal Development Company present individualized digital world.   So this already brings us to our first hurdle. As a result of we’re utilizing a local utility, authenticating customers by means of cookies or periods just isn’t doable. So we’re going to present you the way to put together your React Native utility and your web site to simply accept authenticated requests.   Drupal Development structure Drupal Development structure consists of a vanilla 8 model and a React Native challenge with Redux. Drupal Development carried out stream is as following Drupal 10 Upkeep and Help Service A consumer will get Drupal Development Company login display introduced on Drupal Development Company app. Drupal Development consumer fills in his credentials in Drupal Development Company type Drupal Development app posts Drupal Development Company credentials to Drupal Development Company endpoint in validates Drupal Development Company credentials and logs Drupal Development Company consumer in responds with a token based mostly on Drupal Development Company present consumer Drupal Development app shops Drupal Development Company token for future use Drupal Development app now makes use of Drupal Development Company token for all different requests Drupal Development Company app makes to Drupal Development Company REST API.   Creating an endpoint in First we had to decide on our authentication methodology. On this instance, we opted to authenticate utilizing a JWT or JSON net token, as a result of there already is a superb contributed Drupal 10 module out there for it on .org (https Drupal 10 Upkeep and Help Service//www.Drupal 10.org/challenge/jwt). This Drupal 10 module offers an authentication service that you need to use with Drupal Development Company REST Drupal 10 module that’s now in 8 core. This authentication service will learn Drupal Development Company token that’s handed in Drupal Development Company headers of Drupal Development Company request and can decide Drupal Development Company present consumer from it. All subsequent performance in will then use that consumer to find out if it has permission to entry Drupal Development Company requested sources. This authentication service works for all subsequent requests, however not for Drupal Development Company authentic request to get Drupal Development Company JWT. Drupal Development authentic endpoint Drupal Development Company JWT Drupal 10 module offers, already expects Drupal Development Company consumer to be logged in earlier than it could serve Drupal Development Company token. You would use Drupal Development Company prepared out there fundamental authentication service, however we most popular to construct our personal for instance.   Authentication with JSON submit As an alternative of passing alongside Drupal Development Company username and password in Drupal Development Company headers of Drupal Development Company request like Drupal Development Company fundamental authentication service expects, we’ll ship Drupal Development Company username and password in Drupal Development Company physique of our request formatted as JSON. Our authentication class implements Drupal Development Company AuthenticationProviderInterface and is introduced in json_web_token.providers.yml as follows Drupal 10 Upkeep and Help Service providers Drupal 10 Upkeep and Help Service authentication.json_web_token Drupal 10 Upkeep and Help Service class Drupal 10 Upkeep and Help Service json_web_tokenAuthenticationProviderJsonAuthenticationProvider arguments Drupal 10 Upkeep and Help Service [‘@config.factory’, ‘@user.auth’, ‘@flood’, ‘@entity.manager’] tags Drupal 10 Upkeep and Help Service – { title Drupal 10 Upkeep and Help Service authentication_provider, provider_id Drupal 10 Upkeep and Help Service ‘json_authentication_provider’, precedence Drupal 10 Upkeep and Help Service 100 } Drupal Development interface states that we’ve to implement two strategies, applies and authenticate Drupal 10 Upkeep and Help Service public perform applies(Request $request) { $content material = json_decode($request->getContent()); return isset($content->username, $content->password) && !empty($content->username) && !empty($content->password); } Right here we outline when Drupal Development Company authenticator must be utilized. So our requirement is that Drupal Development Company JSON that’s posted comprises a username and password. In all different circumstances this authenticator might be skipped. Each authenticator service you outline will all the time be referred to as by . Subsequently, it is extremely vital that you just outline your circumstances for making use of Drupal Development Company authentication service. public perform authenticate(Request $request) { $flood_config = $this->configFactory->get(‘consumer.flood’); $content material = json_decode($request->getContent()); $username = $content->username; $password = $content->password; // Flood safety Drupal 10 Upkeep and Help Service that is similar to Drupal Development Company consumer login type code. // @see userFormUserLoginForm Drupal 10 Upkeep and Help Service Drupal 10 Upkeep and Help ServicevalidateAuthentication() // Don’t enable any login from Drupal Development Company present consumer’s IP if Drupal Development Company restrict has been // reached. Default is 50 failed makes an attempt allowed in a single hour. That is // impartial of Drupal Development Company per-user restrict to catch makes an attempt from one IP to log // in to many alternative consumer accounts. We have now a fairly excessive restrict // since there could also be just one obvious IP for all customers at an establishment. if ($this->flood->isAllowed(json_authentication_provider.failed_login_ip’, $flood_config->get(‘ip_limit’), $flood_config->get(‘ip_window’))) { $accounts = $this->entityManager->getStorage(‘consumer’) ->loadByProperties(array(‘title’ => $username, ‘standing’ => 1)); $account = reset($accounts); if ($account) { if ($flood_config->get(‘uid_only’)) { // Register flood occasions based mostly on Drupal Development Company uid solely, so that they apply for any // IP handle. That is Drupal Development Company most safe choice. $identifier = $account->id(); } else { // Drupal Development default identifier is a mixture of uid and IP handle. This // is much less safe however extra immune to denial-of-service assaults that // may lock out all customers with public consumer names. $identifier = $account->id() . ‘-‘ . $request->getClientIP(); } // Do not enable login if Drupal Development Company restrict for this consumer has been reached. // Default is to permit 5 failed makes an attempt each 6 hours. if ($this->flood->isAllowed(‘json_authentication_provider.failed_login_user’, $flood_config->get(‘user_limit’), $flood_config->get(‘user_window’), $identifier)) { $uid = $this->userAuth->authenticate($username, $password); if ($uid) { $this->flood->clear(‘json_authentication_provider.failed_login_user’, $identifier); return $this->entityManager->getStorage(‘consumer’)->load($uid); } else { // Register a per-user failed login occasion. $this->flood->register(‘json_authentication_provider.failed_login_user’, $flood_config->get(‘user_window’), $identifier); } } } } // All the time register an IP-based failed login occasion. $this->flood->register(‘json_authentication_provider.failed_login_ip’, $flood_config->get(‘ip_window’)); return []; } Right here we largely reimplemented Drupal Development Company authentication performance of Drupal Development Company fundamental authorization service, with Drupal Development Company distinction that we learn Drupal Development Company knowledge from a JSON format. This code logs Drupal Development Company consumer into Drupal Development Company utility. All Drupal Development Company further code is flood safety. Getting Drupal Development Company JWT token To get Drupal Development Company JWT token we leveraged Drupal Development Company REST Drupal 10 module, and created a brand new relaxation useful resource plugin. We may have used Drupal Development Company endpoint Drupal Development Company Drupal 10 module already offers, however we desire to create all our endpoints with a model in it. We outlined Drupal Development Company plugin with Drupal Development Company following annotation Drupal 10 Upkeep and Help Service /** * Gives a useful resource to get a JWT token. * * @RestResource( * id = “token_rest_resource”, * label = @Translation(“Token relaxation useful resource”), * uri_paths = { * “canonical” = “/api/v1/token”, * “https Drupal 10 Upkeep and Help Service//www.Drupal 10.org/link-relations/create” = “/api/v1/token” * } * ) */ Drupal Development uri_paths are Drupal Development Company most vital a part of this annotation. By setting each Drupal Development Company canonical and Drupal Development Company bizarre wanting .org keys, we’re capable of set a totally customized path for our endpoint. That permits us to set Drupal Development Company model of our API in Drupal Development Company URI like this Drupal 10 Upkeep and Help Service /api/v1/token. This fashion we will simply roll out new variations of our API and clearly talk about deprecating older variations. Our class extends Drupal Development Company ResourceBase class supplied by Drupal Development Company REST Drupal 10 module. We solely carried out a submit methodology in our class, as we solely need this endpoint to deal with posts. public perform submit() { if($this->currentUser->isAnonymous()){ $knowledge[‘message’] = $this->t(“Login failed. If you do not have an account register. If you happen to forgot your credentials please reset your password.”); }else{ $knowledge[‘message’] = $this->t(‘Login succeeded’); $knowledge[‘token’] = $this->generateToken(); } return new ResourceResponse($knowledge); } /** * Generates a brand new JWT. */ protected perform generateToken() { $token = new JsonWebToken(); $occasion = new JwtAuthDrupal 10 SEOrEvent($token); $this->eventDispatcher->dispatch(JwtAuthDrupal 10 SEOrEvents Drupal 10 Upkeep and Help Service Drupal 10 Upkeep and Help ServiceGENERATE, $occasion); $jwt = $event->getToken(); return $this->transcoder->encode($jwt, array()); } Drupal Development generateToken methodology is a customized methodology the place we leverage Drupal Development Company JWT Drupal 10 module to get us a token that we will return.    We don’t return a JSON object immediately. We return a response in Drupal Development Company type of an array. It is a very useful characteristic of Drupal Development Company REST Drupal 10 module, as a result of you may select Drupal Development Company codecs of your endpoint utilizing Drupal Development Company interface in . So you can simply return another supported format like xml, JSON or hal_json. For this instance, we selected hal_json.  has some built-in safety measures for non-safe strategies. Drupal Development solely secure strategies are HEAD, GET, OPTIONS and TRACE. We’re implementing a non-safe methodology, so we’ve to bear in mind Drupal Development Company following issues Drupal 10 Upkeep and Help Service When Drupal Development Company app does a submit it additionally must ship a X-CSRF-Token in Drupal Development Company header to keep away from cross web site request forgery. This token might be gotten from /session/token endpoint. In case of a POST we additionally must set Drupal Development Company Content material-type request header to “utility/hal+json” on prime of Drupal Development Company question parameter “_format=hal_json”. Placing issues collectively Drupal Development solely factor left is to allow our endpoint by means of Drupal Development Company interface that Drupal Development Company relaxation Drupal 10 modules offers on /admin/config/providers/relaxation. As you may see, we’ve configured our token endpoint with our customized json_authentication_provider service and it’s out there in hal_json and json codecs. Calling Drupal Development Company endpoint in our React Native utility Drupal Development login element Our login element comprise two enter fields and a button. this.setState({username})} placeholderTextColor=”#FFF” fashion={types.enter} /> this.setState({password})} fashion={types.enter} /> this.login({ username Drupal 10 Upkeep and Help Service this.state.username, password Drupal 10 Upkeep and Help Service this.state.password })} > Get Began Once we click on Drupal Development Company login button we set off Drupal Development Company login motion that’s outlined in our bindActions perform. perform bindActions(dispatch) { return { login Drupal 10 Upkeep and Help Service (username, password) => dispatch(login(username, password)), }; } Drupal Development login motion is outlined in our auth.js Drupal 10 Upkeep and Help Service import sort { Motion } from ‘./sorts’; import axios from ‘react-native-axios’; export const LOGIN = ‘LOGIN’; export perform login(username, password) Drupal 10 Upkeep and Help ServiceAction { var jwt = ”; var endpoint = “https Drupal 10 Upkeep and Help Service//instance.com/api/v1/token?_format=hal_json”; return { sort Drupal 10 Upkeep and Help Service LOGIN, payload Drupal 10 Upkeep and Help Service axios({ methodology Drupal 10 Upkeep and Help Service ‘submit’, url Drupal 10 Upkeep and Help Service endpoint, knowledge Drupal 10 Upkeep and Help Service { username Drupal 10 Upkeep and Help Service username, password Drupal 10 Upkeep and Help Service password, jwt Drupal 10 Upkeep and Help Service jwt, }, headers Drupal 10 Upkeep and Help Service { ‘Content material-Sort’ Drupal 10 Upkeep and Help Service’utility/hal+json’, ‘X-CSRF-Token’ Drupal 10 Upkeep and Help Service’V5GBdzli7IvPCuRjMqvlEC4CeSeXgufl4Jx3hngZYRw’ } }) } } On this instance, we set Drupal Development Company X-CSRF-token mounted to maintain it easy. Usually you’d get this primary. We’ve additionally used Drupal Development Company react-native-axios bundle to deal with our submit. This motion will return a promise. If you happen to use Drupal Development Company promise and thunk middleware in your Redux Retailer you may arrange your reducer in Drupal Development Company following manner. import sort { Motion } from ‘../actions/sorts’; import { LOGIN_PENDING, LOGOUT} from ‘../actions/auth’; import { REHYDRATE } from ‘redux-persist/constants’; export sort State = { fetching Drupal 10 Upkeep and Help Service boolean, isLoggedIn Drupal 10 Upkeep and Help Service boolean, username Drupal 10 Upkeep and Help Servicestring, password Drupal 10 Upkeep and Help Servicestring, jwt Drupal 10 Upkeep and Help Service string, error Drupal 10 Upkeep and Help Service boolean, } const initialState = { fetching Drupal 10 Upkeep and Help Service false, username Drupal 10 Upkeep and Help Service ”, password Drupal 10 Upkeep and Help Service ”, error Drupal 10 Upkeep and Help Service null, } export default perform (state Drupal 10 Upkeep and Help ServiceState = initialState, motion Drupal 10 Upkeep and Help ServiceAction) Drupal 10 Upkeep and Help Service State { change (motion.sort) { case “LOGIN_PENDING” Drupal 10 Upkeep and Help Service return {…state, fetching Drupal 10 Upkeep and Help Service true} case “LOGIN_REJECTED” Drupal 10 Upkeep and Help Service return {…state, fetching Drupal 10 Upkeep and Help Service false, error Drupal 10 Upkeep and Help Service motion.payload} case “LOGIN_FULFILLED” Drupal 10 Upkeep and Help Service return {…state, fetching Drupal 10 Upkeep and Help Service false, isLoggedIn Drupal 10 Upkeep and Help Service true, jwt Drupal 10 Upkeep and Help Serviceaction.payload.knowledge.token} case “REHYDRATE” Drupal 10 Upkeep and Help Service var incoming = motion.payload.myReducer if (incoming) return {…state, …incoming, specialKey Drupal 10 Upkeep and Help Service processSpecial(incoming.specialKey)} return state default Drupal 10 Upkeep and Help Service return state; } } Drupal Development reducer will have the ability to act on Drupal Development Company totally different motion sorts of Drupal Development Company promise Drupal 10 Upkeep and Help Service LOGIN_PENDING Drupal 10 Upkeep and Help Service Lets you change Drupal Development Company state of your element so you can implement a loader whereas it’s attempting to get Drupal Development Company token. LOGIN_REJECTED Drupal 10 Upkeep and Help Service When Drupal Development Company try fails you can give a notification why it failed. LOGIN_FULFILLED Drupal 10 Upkeep and Help Service When Drupal Development Company try succeeds you’ve Drupal Development Company token and set Drupal Development Company state to logged in. So as soon as we had carried out all of this, we had an iOS and Android app that really used a 8 web site because it primary content material retailer. Following this instance, you ought to be all set as much as ship tailor-made content material to your customers on whichever platform they could be. Drupal Development objective of this text was to show how efficient 8 might be as a supply to your upcoming iOS or Android utility.   Helpful sources Drupal 10 Upkeep and Help Service 8 Drupal 10 Upkeep and Help Service https Drupal 10 Upkeep and Help Service//www.Drupal 10.org/8 React Native Drupal 10 Upkeep and Help Service https Drupal 10 Upkeep and Help Service//fb.github.io/react-native/ REST fundamentals Drupal 10 Upkeep and Help Service https Drupal 10 Upkeep and Help Service//www.Drupal 10.org/docs/8/core/Drupal 10 modules/relaxation/1-getting-started-rest-configuration-rest-request-fundamentals   Extra articles by our Dropsolid Technical Leads, strategist and marketeers? Test them out right here. Drupal 10 Growth and Help

This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

Dropsolid Drupal 10 Upkeep and Help Service 8 and React Native

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.