# Examples of a redirects file in root folder using netlify ONLY

**URL:** <https://answers.netlify.com/t/examples-of-a-redirects-file-in-root-folder-using-netlify-only/36361>\
**Category:** Support\
**Tags:** redirects\
**Created:** [April 21, 2021, 5:30pm UTC](https://answers.netlify.com/t/examples-of-a-redirects-file-in-root-folder-using-netlify-only/36361 "2021-04-21T17:30:45Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![MM6th](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@MM6th](https://answers.netlify.com/u/MM6th)\
**Post date:** [April 22, 2021, 10:37pm UTC](https://answers.netlify.com/t/examples-of-a-redirects-file-in-root-folder-using-netlify-only/36361/21 "2021-04-22T22:37:00Z")

</div>

O, that’s great to know, and I’m appreciative at all you’ve done.I’ve fixed it locally. When authorizing a page, can I list it like this in the \_redirects? Will my previous redirect remain while this auth command is added? Will this work?

/dating /music 301!  
/film /index 200! Role=member  
/film /film/access-denied/401

---

<div class="post-metadata">

**Author:** ![MM6th](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@MM6th](https://answers.netlify.com/u/MM6th)\
**Post date:** [April 22, 2021, 10:59pm UTC](https://answers.netlify.com/t/examples-of-a-redirects-file-in-root-folder-using-netlify-only/36361/22 "2021-04-22T22:59:36Z")

</div>

Disregard that. It didnt work

---

<div class="post-metadata">

**Author:** ![hrishikesh](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/hrishikesh/32/74607_2.png) [@hrishikesh](https://answers.netlify.com/u/hrishikesh)\
**Post date:** [April 23, 2021, 4:16am UTC](https://answers.netlify.com/t/examples-of-a-redirects-file-in-root-folder-using-netlify-only/36361/23 "2021-04-23T04:16:35Z")

</div>

Yes, you can list it like that. What’s not working?

---

<div class="post-metadata">

**Author:** ![MM6th](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@MM6th](https://answers.netlify.com/u/MM6th)\
**Post date:** [April 23, 2021, 5:48am UTC](https://answers.netlify.com/t/examples-of-a-redirects-file-in-root-folder-using-netlify-only/36361/24 "2021-04-23T05:48:22Z")

</div>

It didn’t prompt me to login, but I think I would need the netlify widget encoded first for that to happen. When I went to code it, when the pressing the link I get the error "failed to load settings from /.netlify/identity

---

<div class="post-metadata">

**Author:** ![hrishikesh](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/hrishikesh/32/74607_2.png) [@hrishikesh](https://answers.netlify.com/u/hrishikesh)\
**Post date:** [April 23, 2021, 8:20am UTC](https://answers.netlify.com/t/examples-of-a-redirects-file-in-root-folder-using-netlify-only/36361/25 "2021-04-23T08:20:59Z")

</div>

Have you enabled Identity for your website?

---

<div class="post-metadata">

**Author:** ![MM6th](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@MM6th](https://answers.netlify.com/u/MM6th)\
**Post date:** [April 23, 2021, 6:28pm UTC](https://answers.netlify.com/t/examples-of-a-redirects-file-in-root-folder-using-netlify-only/36361/26 "2021-04-23T18:28:15Z")

</div>

Yes, and I’ve collected data from forms with it; however, the ultimate goal right now is to find the widget that includes the gmail login option so that I can guard the rest of the site pages for paying members. I coded it once before, but cannot recall how I did it.

---

<div class="post-metadata">

**Author:** ![hrishikesh](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/hrishikesh/32/74607_2.png) [@hrishikesh](https://answers.netlify.com/u/hrishikesh)\
**Post date:** [April 23, 2021, 7:46pm UTC](https://answers.netlify.com/t/examples-of-a-redirects-file-in-root-folder-using-netlify-only/36361/27 "2021-04-23T19:46:32Z")

</div>

There’s not much of coding required. You add the widget and that should do quite a bit.

---

<div class="post-metadata">

**Author:** ![MM6th](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@MM6th](https://answers.netlify.com/u/MM6th)\
**Post date:** [April 23, 2021, 8:17pm UTC](https://answers.netlify.com/t/examples-of-a-redirects-file-in-root-folder-using-netlify-only/36361/28 "2021-04-23T20:17:11Z")

</div>

Right. I figured the same thing. Do you know the widget I speak of? Is it possible that you can copy and paste it into this thread?

This is what I have, but the popup results in error

 A static website 

Login with Netlify Identity

---

<div class="post-metadata">

**Author:** ![hrishikesh](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/hrishikesh/32/74607_2.png) [@hrishikesh](https://answers.netlify.com/u/hrishikesh)\
**Post date:** [April 23, 2021, 8:51pm UTC](https://answers.netlify.com/t/examples-of-a-redirects-file-in-root-folder-using-netlify-only/36361/29 "2021-04-23T20:51:01Z")

</div>

This guide covers a lot of it: [Authenticate users with Netlify Identity | Netlify Docs](https://docs.netlify.com/visitor-access/identity/) and should help you get started.

---

<div class="post-metadata">

**Author:** ![MM6th](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@MM6th](https://answers.netlify.com/u/MM6th)\
**Post date:** [August 24, 2021, 10:03am UTC](https://answers.netlify.com/t/examples-of-a-redirects-file-in-root-folder-using-netlify-only/36361/30 "2021-08-24T10:03:45Z")

</div>

I’ve checked it out (the link) and after some more coding with JavaScript am getting a better idea of what’s going on. From your experience, where the gotrue API asks to confirm and respond with emails, can we replace emails with “mobile numbers”?

---

<div class="post-metadata">

**Author:** ![hrishikesh](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/hrishikesh/32/74607_2.png) [@hrishikesh](https://answers.netlify.com/u/hrishikesh)\
**Post date:** [August 24, 2021, 10:09am UTC](https://answers.netlify.com/t/examples-of-a-redirects-file-in-root-folder-using-netlify-only/36361/31 "2021-08-24T10:09:29Z")

</div>

Hi @MM6th,

While that might work (I have no idea if it really will and would be inclined to think it’s not possible), I’d strongly advise against it. The email is important for users to be able to reset their password or confirm the email in the first place. Thus, changing that would be a bad idea.

---

<div class="post-metadata">

**Author:** ![MM6th](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@MM6th](https://answers.netlify.com/u/MM6th)\
**Post date:** [August 24, 2021, 10:19am UTC](https://answers.netlify.com/t/examples-of-a-redirects-file-in-root-folder-using-netlify-only/36361/32 "2021-08-24T10:19:38Z")

</div>

But doesn’t the same process apply with a phone number? A message gets sent telling you to click a link (I’ve yet to subscribe any members to my site yet)

---

<div class="post-metadata">

**Author:** ![hrishikesh](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/hrishikesh/32/74607_2.png) [@hrishikesh](https://answers.netlify.com/u/hrishikesh)\
**Post date:** [August 24, 2021, 10:23am UTC](https://answers.netlify.com/t/examples-of-a-redirects-file-in-root-folder-using-netlify-only/36361/33 "2021-08-24T10:23:52Z")

</div>

Hi @MM6th,

The backend is not yet configured to send SMS messages. It can only send emails.

---

<div class="post-metadata">

**Author:** ![MM6th](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@MM6th](https://answers.netlify.com/u/MM6th)\
**Post date:** [August 24, 2021, 10:34am UTC](https://answers.netlify.com/t/examples-of-a-redirects-file-in-root-folder-using-netlify-only/36361/34 "2021-08-24T10:34:49Z")

</div>

Understood. One again thanks a lot!

---

<div class="post-metadata">

**Author:** ![MM6th](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@MM6th](https://answers.netlify.com/u/MM6th)\
**Post date:** [August 24, 2021, 12:46pm UTC](https://answers.netlify.com/t/examples-of-a-redirects-file-in-root-folder-using-netlify-only/36361/35 "2021-08-24T12:46:34Z")

</div>

I installed yarn, and went to code the gotrue-js API but there are soooo many. It’s confusing. I chose the admin method which I’ll paste here:

document.querySelector(“form[name=‘login’]”).addEventListener(“submit”, e =\> {  
e.preventDefault();  
const form = e.target;  
const { email, password } = form.elements;  
auth  
.login(email.value, password.value, true)  
.then(response =\> {  
const myAuthHeader = “Bearer " + response.token.access\_token; //creates the bearer token  
fetch(”/.netlify/functions/hello", {  
headers: { Authorization: myAuthHeader },  
credentials: “include”  
})  
.then(response =\> {  
console.log({ response });  
})  
.catch(error =\> {…});  
})  
.catch(error =\> {…});  
});

I have this coded below a custom register and flip login card. Will this handle registry and login?

---

<div class="post-metadata">

**Author:** ![hrishikesh](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/hrishikesh/32/74607_2.png) [@hrishikesh](https://answers.netlify.com/u/hrishikesh)\
**Post date:** [August 24, 2021, 1:39pm UTC](https://answers.netlify.com/t/examples-of-a-redirects-file-in-root-folder-using-netlify-only/36361/36 "2021-08-24T13:39:59Z")

</div>

Hi @MM6th,

Yes, this would do fine to login. Here’s a complete code including the import statement:

```auto
const loginForm = document.querySelector('form[name="login"]')
loginForm.addEventListener('submit', event => {
  event.preventDefault()
  const { email, password } = loginForm.elements
  auth.login(email.value, password.value, true).then(response => {
    fetch('/.netlify/functions/bar', {
      headers: {
        Authorization: "Bearer " + response.token.access_token
      }
    }).then(response => {
      if (response.ok) {
        return response.json()
      } else {
        throw response.status
      }
    }).then(data => {
      console.log(data)
    }).catch(error => {
      console.log(error)
    })
  }).catch(error => {
    console.log(error)
  })
})

```

Inside the function, you’d have to set the user roles and return it back to the client.

Additionally, you could also use Netlify Identity Widget to handle a lot of this automatically.

---

<div class="post-metadata">

**Author:** ![MM6th](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@MM6th](https://answers.netlify.com/u/MM6th)\
**Post date:** [August 24, 2021, 1:53pm UTC](https://answers.netlify.com/t/examples-of-a-redirects-file-in-root-folder-using-netlify-only/36361/37 "2021-08-24T13:53:20Z")

</div>

Wow! Thanks! I tried but kept getting an error, so I customized a login and came to this. So , you’re saying assign the role and it will automate right? But I have to go live and do it. I can’t troubleshoot it from local host.

---

<div class="post-metadata">

**Author:** ![hrishikesh](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/hrishikesh/32/74607_2.png) [@hrishikesh](https://answers.netlify.com/u/hrishikesh)\
**Post date:** [August 24, 2021, 1:56pm UTC](https://answers.netlify.com/t/examples-of-a-redirects-file-in-root-folder-using-netlify-only/36361/38 "2021-08-24T13:56:24Z")

</div>

Hi @MM6th,

I’ll explain the flow how Role Based Access Control will work:

A user signs-up → they have no role set → they subscribe to a premium plan → you handle the payment and trigger a serverless function once they’ve successfully paid → upgrade their role in the function → return the user data with the updated role and send a cookie named `nf_jwt` → RBAC will match this cookie to redirect in the future.

Does this shed some light?

---

<div class="post-metadata">

**Author:** ![MM6th](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@MM6th](https://answers.netlify.com/u/MM6th)\
**Post date:** [August 24, 2021, 2:01pm UTC](https://answers.netlify.com/t/examples-of-a-redirects-file-in-root-folder-using-netlify-only/36361/39 "2021-08-24T14:01:56Z")

</div>

It sounds so encouraging, and I wish it did ring a bell but it doesn’t lol. I do know I can adjust my form for an initial sign up, and I do have a premium page where they have to pay in crypto. When you say return function is that regarding the return function in this code? I’ve coded a mean site but have never gotten this far

---

<div class="post-metadata">

**Author:** ![hrishikesh](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/hrishikesh/32/74607_2.png) [@hrishikesh](https://answers.netlify.com/u/hrishikesh)\
**Post date:** [August 24, 2021, 2:12pm UTC](https://answers.netlify.com/t/examples-of-a-redirects-file-in-root-folder-using-netlify-only/36361/40 "2021-08-24T14:12:01Z")

</div>

> [@MM6th](#):
>
> When you say return function is that regarding the return function in this code?

Oh, I am talking about the serverless function that you’d write to update the user role, like this one here:

> [@MM6th](#):
>
> fetch(”/.netlify/functions/hello"

You’d have to set the role in this function using one of the admin methods of GoTrueJS. Once it’s set, you’d have to return the user back to client. Here’s an example:

> [@Updating users roles via Netlify Serverless function (When logged in as another user)](https://answers.netlify.com/t/updating-users-roles-via-netlify-serverless-function-when-logged-in-as-another-user/41459/26):
>
> ```auto
> return fetch(`${identity.url}/admin/users/${payload.netlifyId}`, {
> method: 'put',
> body: JSON.stringify({
> app_metadata: {
> roles: [payload.role]
> }
> }),
> headers: {
> Authorization: `Bearer ${identity.token}`
> }
> }).then(response => {
> return response.json()
> }).then(updatedUser => {
> return {
> statusCode: 200,
> body: JSON.stringify(updatedUser)
> }
> })
> 
> ```

Taken from:

> [@Updating users roles via Netlify Serverless function (When logged in as another user)](https://answers.netlify.com/t/updating-users-roles-via-netlify-serverless-function-when-logged-in-as-another-user/41459/26):
>
> So, according to the discussion we had, the code was working fine for a small number of users. But, @carvill had around 14k users where this code was failing. Chances are, the size of the users array was getting more than what a serverless function could handle. Thus, the solution was to store the identity user ID in an external database which you can query. Then, you just have to pass the ID with the payload and in the function, change role like: const fetch = require('node-fetch') exports.ha…

`updatedUser` is the object you’d get here:

> [@hrishikesh](#):
>
> ```auto
> .then(data => {
> console.log(data)
> })
> 
> ```

[Previous page](https://answers.netlify.com/t/examples-of-a-redirects-file-in-root-folder-using-netlify-only/36361.md?page=1)

[Next page](https://answers.netlify.com/t/examples-of-a-redirects-file-in-root-folder-using-netlify-only/36361.md?page=3)
