Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next.js Integration #378

Open
vicesalles opened this issue Mar 17, 2020 · 2 comments
Open

Next.js Integration #378

vicesalles opened this issue Mar 17, 2020 · 2 comments

Comments

@vicesalles
Copy link

I'm trying to use Stitch from a Next.js app and I'm getting a 'self is not defined' error. I'd like to see an example where Stitch runs nice with next.js. Is that possible?

@SheaBelsky
Copy link

As far as I know, it's not possible with Next.js. Stitch doesn't appear to support isomorphic apps.

There's a workaround posted here, but I wasn't able to get it to work for me. If you can get it to work, could you let me know?

#186 (comment)

#186 (comment)

@daploydev
Copy link

daploydev commented Jun 1, 2020

I was able to get anonymous auth in next js I have a _app.js file with a layout.js component inside my layout.js: import Head from 'next/head' then in the head I used the sdk script tag
<Head> <title>{title}</title> <meta charSet="utf-8" /> <meta name="viewport" content="initial-scale=1.0, width=device-width" /> <script src="https://s3.amazonaws.com/stitch-sdks/js/bundles/4/stitch.js"></script> <script src="/auth.js"></script> </Head>

create an auth.js file in the public dir with this code:
const clientstitch = stitch.Stitch.initializeDefaultAppClient('YOUR-APP-ID');

function initializeAndLogin() {
clientstitch.auth
.loginWithCredential(new stitch.AnonymousCredential())
.catch(console.error);
document.getElementById('auth-status').innerHTML =
'Logged in as anonymous user with id ${clientstitch.auth.user.id}';
}
window.onload = initializeAndLogin;

I then added this div into a component <div id="auth-status">Logged Out</div> this will display the user id as soon as its received. I am getting a user id and when I look at my stitch app it shows the user that gets generated. If anyone has any ideas of how we can use apollo client 3 to use graphql endpoint that is where I am stuck now just getting a 401 so i need to pass that authenticated user in the apollo request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants