writeWebAuthCookie method
If isWebAuthCookieRequest, writes token as the auth cookie and returns
true. Otherwise returns false and the caller should return the token in
the response body as usual. maxAgeSeconds sets the cookie lifetime;
omit it for a session cookie.
Implementation
bool writeWebAuthCookie(String token, {int? maxAgeSeconds}) {
if (!isWebAuthCookieRequest) return false;
// isWebAuthCookieRequest already proved authCookie is non-null.
setResponseCookie(
serverpod.config.authCookie!.buildSetCookieHeader(
token,
maxAgeSeconds: maxAgeSeconds,
),
);
return true;
}