Comment on page
checkSession
import React, { useEffect, useState } from 'react';
import { useSlashAuth } from '@slashauth/slashauth-react';
export const CheckSession = () => {
const { checkSession } = useSlashAuth();
const [hasSession, setHasSession] = useState(false);
useEffect(() => {
checkSession().then((session) => setHasSession(session));
}, [checkSession]);
return <div>{`Does user have a session? ${hasSession}`}</div>;
}
boolean
If true, the full response from the /oauth/token endpoint (or the cache, if the cache was used) is returned (minus
refresh_token
if one was issued). Otherwise, just the access token is returned. import React, { useEffect, useState } from 'react';
import { useSlashAuth } from '@slashauth/slashauth-react';
export const CheckSession = () => {
const { checkSession } = useSlashAuth();
const [hasSession, setHasSession] = useState(false);
useEffect(() => {
checkSession({ ignoreCache: true }).then((session) =>
setHasSession(session)
);
}, [checkSession]);
return <div>{`Does user have a session? ${hasSession}`}</div>;
};
A maximum number of seconds to wait before declaring the background /authorize call as failed for timeout Defaults to 60s.
import React, { useEffect, useState } from 'react';
import { useSlashAuth } from '@slashauth/slashauth-react';
export const CheckSession = () => {
const { checkSession } = useSlashAuth();
const [hasSession, setHasSession] = useState(false);
useEffect(() => {
checkSession({ timeoutInSeconds: 30 }).then((session) =>
setHasSession(session)
);
}, [checkSession]);
return <div>{`Does user have a session? ${hasSession}`}</div>;
};
If you need to send custom parameters to the Authorization Server, make sure to use the original parameter name.
import React, { useEffect, useState } from 'react';
import { useSlashAuth } from '@slashauth/slashauth-react';
export const CheckSession = () => {
const { checkSession } = useSlashAuth();
const [hasSession, setHasSession] = useState(false);
useEffect(() => {
checkSession({ detailedResponse: true }).then((session) =>
setHasSession(session)
);
}, [checkSession]);
return <div>{`Does user have a session? ${hasSession}`}</div>;
};
Last modified 10mo ago