2022年6月24日星期五

simple react login auth (laravel)

 welcome.blade.php

<script src="{{ asset('js/app.js') }}" defer></script>
<link rel="stylesheet" href="{{ asset('css/app.css') }}">
<div id="example" token='{{ csrf_token() }}' route_login='{{route('login')}}' ></div>

Example.js

import React from 'react';
import ReactDOM from 'react-dom';


function Example(props) {
    return (
        <div className="container">
            <br />

            <div className="card" >

                <div className="card-body">
                    <h5 className="card-title">Login</h5>
                    <form method="POST" action={props.route_login} >
                        <input type="hidden" name="_token" value={props.token} />
                        <label for="email">Email:</label><br />
                        <input type="text" id="email" name="email" /><br />
                        <label for="password">Password:</label><br />
                        <input type="text" id="password" name="password" /><br /><br />
                        <input type="submit" value="Submit" />
                    </form>
                </div>
            </div>
        </div>
    );
}

export default Example;


if (document.getElementById('example')) {
    var _token = document.getElementById('example').getAttribute('token');
    var _route_login = document.getElementById('example').getAttribute('route_login');
    ReactDOM.render(<Example token={_token} route_login={_route_login} />, document.getElementById('example'));
}

沒有留言:

發佈留言

[Fixed] some windows chrome, scrolling has glitch position not accurate

   [Fixed] some windows chrome, scrolling has glitch position not accurate Smooth Scrolling Flag 📜 Chrome has an experimental "smooth ...