Sierra guide / Resources
Signed-in state
session is the browser's idea of who is signed in: a reactive object with user, level, checked and error, next to signIn, signUp and signOut. Declaring publicRoutes in the junction config guards every other route, and a 401 from any call signs the page out.
export default {
junction: {
url: 'http://localhost:8000',
cookieAuth: true, // only if the server issues a cookie
auth: { publicRoutes: ['/login/', '/blog/*'], redirectTo: '/login/', returnPath: true },
},
}
<script>
import { session, signOut } from '@frontierjs/sierra/resource'
$: session.user
</script>
{#if session.user}<button onclick={signOut}>Sign out {session.user.email}</button>{/if}
This page has no running example: a sign-in needs a browser and a server that issues a credential.
What else it can do
cookieAuthis declared on the server asauth(auth, { cookieAuth: true })and here, and the two must agree- A trailing
*inpublicRoutescovers the path and everything under it, so/blog/*leaves/blogadminguarded redirectTois where an unauthorized page goes, andreturnPath: truebrings it back after sign-in- The guard checks that a credential is present, and the server decides whether it is valid
session.levelfeedsresource.can(op, level), and the server grades every call regardless
In depth: Sierra README § Auth