Examples of a redirects file in root folder using netlify ONLY

Ok, so the first piece of code is for when they are first registering, followed by the “fetch”, followed by the code underneath which substantiates them as a payee (and admins too I think I see). Does all of this code get pasted into the initial registry page? Or both registry page and login page? And is there a manual intervention I have to take to verify they paid?

The code I linked to in the other post is all handled in the serverless function. You can’t do this in the client-side code and if you try to do it, it’d be a huge security risk as anyone could do it for themselves.

Basically, this is how you’d go: signup (client-side) → pay (client-side) → update role using serverless function (server side).

1 Like

So, only this code gets pasted into my login.html page (server side)

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)
}
})

?
Bare with me
I’m trying to simplify this as much as I can so I understand

Well, it’s not any page, it’s server side. It goes in your Netlify Functions like explained here:

You can call the function from any page on your website or even externally.

1 Like

My OS rejected “npm install netlify-cli -g” as suggested in the functions section

It’s a socket issue I have to fix. I’ll catch up with you. Thanks again for pointing me in the right direction.

I need to revive this topic because I have finally done the netlify registration widget

Hi, @MM6th. I’m not sure what you mean by “revive”. You made a post here today so the topic is “revived”.

Did you have a question?

1 Like

Yes. Hopefully I closed out the old post, and my new question posted. My question is how do I code my redirect file to direct users only to particular page in my website after logging in?

You have already opened a new thread for this question @MM6th

1 Like

Yes

/login /library 200! Role=admin

Above is what I have in my redirects file but after I login I’m staying on the login page instead of going to my library page

Have you seen the Role-based redirects documentation @MM6th?

As explained in HTTP Status Codes, 200 does not redirect, it means OK.

You might try something like

/library/*    200!  Role=admin
/library/*   /login    401! 

which would load anything under the path /library for a user with the admin role, otherwise show the login page.

1 Like

Yes I glanced at it and believed Ok meant just that, but I see 401 and what you have here … what does 401 mean? I’m going to try this right now

Before I follow through. I tried the code you provided in netlify playground and this came back:

/library/* 200! Role=admin : the target URL is missing, it should either start with / or be an absolute URL

It means Unauthorized.

Have you tried it on your account?

It’s exactly as per the first example in the Netlify documentation here:

The playground isn’t infallible, I’ve seen it indicate that various rules will/won’t work when they actually do/don’t against a real site.

As the documentation indicates that the role based redirects happen at the CDN edge, I’d suspect they aren’t processed by exactly the same code as the other redirects/playground.

1 Like

I just looked at it on the link and you’re right… Also yes I just tried it on my account, and the upload said redirects file uploaded with a change but with no errors, however when I logged in the page remains on the login page.

Just to confirm, this is all I need right?

Login
Login with Netlify Identity
.

The rules specified don’t redirect, they allow/prevent access to the routes.

Have you tried a rule that does redirect?

E.g.

/login    /library    302!    Role=admin

I’ve never used this functionality so it may not work, but it’s worth a shot.

1 Like

To no avail, but thanks!

Can you explain what you are trying to accomplish with redirects @MM6th? Are you trying to prevent access, allow access, or redirect on login/logout/unauthorised access, to a specific asset/location?

1 Like