Skip to content

Commit

Permalink
Adding firebase auth docs
Browse files Browse the repository at this point in the history
  • Loading branch information
intricatecloud committed Apr 8, 2024
1 parent a776d22 commit 5ce11e5
Show file tree
Hide file tree
Showing 8 changed files with 202 additions and 181 deletions.
12 changes: 0 additions & 12 deletions docs/2024-01-24-qm45.md

This file was deleted.

56 changes: 34 additions & 22 deletions docs/unit-2/backend-apis/developing-apis.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ sidebar_class_name: hidden

In this section, we'll cover how you can create the API routes to support our example chatroom application. We'll create our API routes that we defined in the [earlier page](./define-rest-api)

All the code used here is pulled from the NextJS docs on [API routes using the Pages router](https://nextjs.org/docs/pages/building-your-application/routing/api-routes).

For each API route, I'll include some code for how to read the response using `fetch()`.

## Notes
Expand All @@ -21,26 +23,20 @@ export default async function handler(req, res) {
const session = await getServerSession(req, res)

if (req.method === 'POST') {
// Handle GET request

} else if (req.method === 'POST') {
// Handle POST request
const name = req.body.name
await db.createUser(name)
return res.status(201).json({name})
} else {
return res.status(501).json({ message: 'Not implemented yet' })
}
}


app.post('/user', (request, response) => {
const name = request.body.name

db.createUser(name)

response.status(201).send(name)
})
```

Make a request

```js
fetch('/user', {
fetch('/api/user', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
Expand All @@ -54,19 +50,24 @@ fetch('/user', {

Note - this is copied from the previous section. Included for completeness.

```js title="app.js"
app.post('/chatroom', (request, response) => {
const name = request.body.name

db.createChatroom(name)
```js title="pages/api/chatroom/index.js"
export default async function handler(req, res) {
const session = await getServerSession(req, res)

response.status(201).send(name)
})
if (req.method === 'POST') {
// Handle POST request
const name = req.body.name
await db.createChatroom(name)
return res.status(201).json({name})
} else {
return res.status(501).json({ message: 'Not implemented yet' })
}
}
```
Make the request

```js
fetch('/chatroom', {
fetch('/api/chatroom', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
Expand All @@ -79,7 +80,18 @@ fetch('/chatroom', {

## Join a Chatroom

```js title="app.js"
```js title="pages/api/chatroom/[name].js"
export default async function handler(req, res) {
const session = await getServerSession(req, res)

if (req.method === 'PUT') {
const name = req.body.name
await db.createUser(name)
return res.status(201).json({name})
} else {
return res.status(501).json({ message: 'Not implemented yet' })
}
}
// highlight-next-line
app.put('/chatroom/:name', (request, response) => {
// highlight-next-line
Expand Down
2 changes: 1 addition & 1 deletion docs/unit-2/frontend/working-with-forms.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Forms refer to the `<form>` element, and the patterns for moving the data around

The pattern is:
* Create a Form element
* Add some input elements based on the data you want to provide
* Add some input elements b ased on the data you want to provide
* Add a submit button
* When the submit button is clicked, do something with the form values

Expand Down
1 change: 0 additions & 1 deletion docs/unit-3/_category_.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
"type": "generated-index",
"description": "Everything you need to know to build your own Web App with an API, and host & monitor it."
},
"className": "hidden"
}
Loading

0 comments on commit 5ce11e5

Please sign in to comment.