View example-1.js
for (var k = 0; k < 5; k++) { | |
console.log(k); // 0, 1, 2, 3, 4 | |
} | |
console.log(k); //5 because k is global |
View helloworld.html
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>Hello World!</title> | |
</head> | |
<body> | |
<main id="app"> |
View cmd1.bash
npm install express cors body-parser dotenv stream-chat --save |
View .env
// .env | |
STREAM_API_KEY=<your api key> | |
STREAM_APP_SECRET=<your app secret> |
View server.js
require('dotenv').config(); | |
const express = require('express'); | |
const cors = require('cors'); | |
const bodyParser = require('body-parser'); | |
const { StreamChat } = require('stream-chat'); | |
const app = express(); | |
app.use(cors()); |
View cmd2.bash
npm install @auth0/auth0-spa-js |
View auth0.js
import React, { useState, useEffect, useContext } from 'react'; | |
import createAuth0Client from '@auth0/auth0-spa-js'; | |
const DEFAULT_REDIRECT_CALLBACK = () => | |
window.history.replaceState({}, document.title, window.location.pathname); | |
export const Auth0Context = React.createContext(); | |
export const useAuth0 = () => useContext(Auth0Context); | |
export const Auth0Provider = ({ | |
children, |
View index.js
import React from 'react'; | |
import ReactDOM from 'react-dom'; | |
import App from './App'; | |
import * as serviceWorker from './serviceWorker'; | |
import { Auth0Provider } from './auth0'; | |
ReactDOM.render( | |
<Auth0Provider | |
domain={"<your domain>"} | |
client_id={"<your client id>"} |
View App.js
import React, { useEffect } from 'react'; | |
import './App.css'; | |
import { useAuth0 } from './auth0'; | |
function App() { | |
useEffect(() => {}, []); | |
const { loading, user, loginWithRedirect } = useAuth0(); | |
if (loading) { |
View App.css
html { | |
box-sizing: border-box; | |
} | |
*, *::before, *::after { | |
box-sizing: inherit; | |
margin: 0; | |
padding: 0; | |
} |
OlderNewer