An alias to elm's Platform.Program providing the type signature for a PostgRestAdmin program.
Creates a default configuration.
main : PostgRestAdmin.Program
main =
PostgRestAdmin.configure
|> PostgRestAdmin.host "http://localhost:3000"
|> PostgRestAdmin.onLogin loginSuccess
|> PostgRestAdmin.buildProgramConverts a Config into a Program.
Callback triggered with a JWT string on successful login. Typically used to persist the JWT to session storage.
port loginSuccess : String -> Cmd msg
main : PostgRestAdmin.Program
main =
PostgRestAdmin.configuration
|> PostgRestAdmin.onLogin loginSuccess
|> PostgRestAdmin.buildProgramThen subscribe to the corresponding port.
app.ports.loginSuccess.subscribe(jwt => {
sessionStorage.setItem("jwt", jwt)
});Callback triggered when authentication fails when attempting to perform a request. You can use this to perform external authentication.
port authFailure : String -> Cmd msg
port tokenReceiver :
({ path : String, accessToken : String } -> msg)
-> Sub msg
main : PostgRestAdmin.Program
main =
PostgRestAdmin.configuration
|> PostgRestAdmin.onAuthFailed authFailure
|> PostgRestAdmin.onExternalLogin tokenReceiver
|> PostgRestAdmin.buildProgramThen wire to the corresponding ports.
app.ports.authFailure.subscribe(requestedPath => {
authenticate(requestedPath).then((accessToken) => {
app.ports.tokenReceiver.send({
path : requestedPath,
accessToken : accessToken
})
})
});Callback triggered when the user logs out. You can use this to perform cleanup or external logout operations.
port logout : () -> Cmd msg
main : PostgRestAdmin.Program
main =
PostgRestAdmin.configuration
|> PostgRestAdmin.onLogout logout
|> PostgRestAdmin.buildProgramThen subscribe to the corresponding port.
app.ports.logout.subscribe(_ => {
externalLogout()
});Subscribe to receive a JWT and a redirect path when login with an external provider.
See onAuthFailed.
Specify the PostgREST host.
main : PostgRestAdmin.Program
main =
PostgRestAdmin.configuration
|> PostgRestAdmin.withHost "http://localhost:3000"
|> PostgRestAdmin.buildProgramSpecify the login URL for form authentication.
main : PostgRestAdmin.Program
main =
PostgRestAdmin.configuration
|> PostgRestAdmin.withLoginUrl "http://localhost:3000/rpc/login"
|> PostgRestAdmin.buildProgramSet a JWT to authenticate PostgREST requests. You can set an initial JWT using this attribute.
main : PostgRestAdmin.Program
main =
PostgRestAdmin.configuration
|> PostgRestAdmin.withJWT "8abf3a...9ac36d"
|> PostgRestAdmin.buildProgramSet default HTTP headers to be included in all Client requests. This is
useful for setting headers like Accept-Profile or Content-Profile when
working with PostgREST schemas.
main : PostgRestAdmin.Program
main =
PostgRestAdmin.configuration
|> PostgRestAdmin.withClientHeaders
[ Http.header "Accept-Profile" "bluebox"
, Http.header "Content-Profile" "bluebox"
]
|> PostgRestAdmin.buildProgramIf set to False no attempt to decode and apply flags will be made. Defaults to true.
main : PostgRestAdmin.Program
main =
PostgRestAdmin.configuration
|> PostgRestAdmin.withFlags False
|> PostgRestAdmin.buildProgram
-- Flags are ignoredSpecify a path prefix for all routes, in case the app is not mounted in the root path.
main : PostgRestAdmin.Program
main =
PostgRestAdmin.configuration
|> PostgRestAdmin.withMountPath "/back-office"
|> PostgRestAdmin.buildProgramSet the number of records to display per page in listing views.
main : PostgRestAdmin.Program
main =
PostgRestAdmin.configuration
|> PostgRestAdmin.withRecordsPerPage 100
|> PostgRestAdmin.buildProgramPass a list of links to display in the side menu. The list consists of tuples of the link text and a url.
main : PostgRestAdmin.Program
main =
PostgRestAdmin.configuration
|> PostgRestAdmin.withMenuLinks [ ( "Api Docs", "/api/docs" ) ]
|> PostgRestAdmin.buildProgramSpecify which fields should be present in the edit and create forms, overriding the table schema. By default a primary key field is not present in the forms.
main : PostgRestAdmin.Program
main =
PostgRestAdmin.configuration
|> PostgRestAdmin.withFormFields "posts" [ "id", "title", "content" ]
|> PostgRestAdmin.buildProgramPass a list of table names to restrict the editable resources, also sets the order of the left resources menu.
main : PostgRestAdmin.Program
main =
PostgRestAdmin.configuration
|> PostgRestAdmin.withTables [ "posts", "comments" ]
|> PostgRestAdmin.buildProgramRename a table referenced in a foreign key. PostgREST OpenAPI generated docs confuse tables with views when describing the foreign key for a resource, because of this some links might be incorrectly generated.
main : PostgRestAdmin.Program
main =
PostgRestAdmin.configuration
|> PostgRestAdmin.withTableAliases
(Dict.fromList [ ( "published_posts", "posts" ) ])
|> PostgRestAdmin.buildProgramDisplay a banner text below the login form. The text is rendered as markdown.
main : PostgRestAdmin.Program
main =
PostgRestAdmin.configuration
|> PostgRestAdmin.withLoginBannerText "**Welcome!** Please login to continue."
|> PostgRestAdmin.buildProgram