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

Add User Management Examples to Repository #3

Closed
DieHard073055 opened this issue May 14, 2023 · 0 comments · Fixed by #4
Closed

Add User Management Examples to Repository #3

DieHard073055 opened this issue May 14, 2023 · 0 comments · Fixed by #4
Assignees
Labels
good first issue Good for newcomers

Comments

@DieHard073055
Copy link
Owner

Description:

The current repository provides a great starting point for using Supabase. However, it would be beneficial to include some practical examples of user management, specifically:

  1. Creating a user / signing up
  2. Logging in using the user
  3. Deleting the user

Here's a brief outline of what the examples could look like:

  1. Creating a user / signing up:
const { createClient } = require("@supabase/supabase-js");

const supabaseUrl = process.env.SUPABASE_URL;
const supabaseAnonKey = process.env.SUPABASE_ANON_KEY;

const supabase = createClient(supabaseUrl, supabaseAnonKey);

const signUpUser = async (email, password) => {
  const { user, error } = await supabase.auth.signUp({
    email: email,
    password: password,
  });

  if (error) console.error(error);
  else console.log(user);
};

signUpUser('[email protected]', 'example-password');
  1. Logging in using the user:
const loginUser = async (email, password) => {
  const { user, session, error } = await supabase.auth.signIn({
    email: email,
    password: password,
  });

  if (error) console.error(error);
  else console.log('User:', user, 'Session:', session);
};

loginUser('[email protected]', 'example-password');
  1. Deleting the user:
const fetch = require('node-fetch');
const url = 'https://<your-supabase-project>.supabase.co/auth/v1/remove';

const deleteUserData = async (accessToken) => {
  const response = await fetch(url, {
    method: 'DELETE',
    headers: {
      'Authorization': `Bearer ${accessToken}`,
      'Content-Type': 'application/json'
    },
  });
  const data = await response.json();
  console.log(data);
};
deleteUserData('<access-token>');

(Note: Replace and with your actual values.)

Incorporating these examples into our repository would provide a more comprehensive introduction to the capabilities of Supabase and help developers understand how to implement these common tasks.

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

Successfully merging a pull request may close this issue.

2 participants